-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputs.py
136 lines (124 loc) · 3.06 KB
/
inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from dotenv import load_dotenv
import os
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from datetime import date
import arrow
load_dotenv()
mongopw = os.getenv("mongopw")
# DATES AND TIMES
utcnow = arrow.utcnow()
pstnow = utcnow.to('US/Pacific')
today = pstnow.date()
# League Size
numTeams = 12
# mongo stuff
uri = f"mongodb+srv://admin:{mongopw}@cluster0.nfj4j.mongodb.net/?retryWrites=true&w=majority"
client = MongoClient(uri, server_api=ServerApi('1'))
def mongoConnect(year = "2023"):
db = client["wfbc" + year]
return db
# teams
def getTeams(year):
db = mongoConnect(year)
_teams = db.teams.find()
teams = []
for team in _teams:
teams.append({
'manager' : team['manager'],
'team_id' : team['team_id'],
'team_name' : team['team_name']
})
return teams
# MLB regular season season start and end dates, league IDs
seasons = {
"2011" :
{
"leagueID" : "812"
},
"2012" :
{
"leagueID" : "438"
},
"2013" :
{
"leagueID" : "393"
},
"2014" :
{
"leagueID" : "549"
},
"2015" :
{
"leagueID" : "288"
},
"2016" :
{
"leagueID" : "82"
},
"2017" :
{
"leagueID" : "153"
},
"2018" :
{
"leagueID" : "151"
},
"2019" :
{
"start" : date(2019, 3, 20),
"end" : date(2019, 9, 29),
"leagueID" : "56"
},
"2020" :
{
"start" : date(2020, 7, 23),
"end" : date(2020, 9, 27),
"leagueID" : "163"
},
"2021" :
{
"start" : date(2021, 4, 1),
"end" : date(2021, 10, 3),
"leagueID" : "56"
},
"2022" :
{
"start" : date(2022, 4, 7),
"end" : date(2022, 10, 5),
"leagueID" : "4"
},
"2023" :
{
"start" : date(2023, 3, 30),
"end" : date(2023, 10, 1),
"leagueID" : "13"
},
"2024" :
{
"start" : date(2024, 3, 20),
"end" : date(2024, 9, 29),
"leagueID" : "62"
}
}
def getStartDate(year):
return seasons[year]["start"]
def getEndDate(year):
return seasons[year]["end"]
# box score endpoint
# https://www.rotowire.com/mlbcommish24/tables/box.php?leagueID=62&teamID=601&borp=B
# roster endpoint
# https://www.rotowire.com/mlbcommish24/tables/rosters.php?leagueID=62&teamID=595
# API endpoints
endpoint = "https://www.rotowire.com/mlbcommish"
def getRosterEndpoint(year, teamID):
shortYear = year[2:]
rosterEndpoint = endpoint + shortYear + "/tables/rosters.php?leagueID=" + seasons[year]["leagueID"] + "&teamID=" + teamID
return rosterEndpoint
def getBoxEndpoint(year, teamID, date, hittingOrPitching):
shortYear = year[2:]
if teamID == "first":
teams = getTeams(year)
teamID = teams[0]['team_id']
boxEndpoint = endpoint + shortYear + "/tables/box.php?leagueID=" + seasons[year]["leagueID"] + "&teamID=" + teamID + "&date=" + date + "&borp=" + ("B" if hittingOrPitching == "hitting" else "P")
return boxEndpoint