-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
148 lines (127 loc) · 4.31 KB
/
app.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
137
138
139
140
141
142
143
144
145
146
147
148
import numpy as np
from pandas import DataFrame
import yaml
from pathlib import Path
from time import time
from Mom_WeeklyRankings_Export.utils import (
get_laborday,
nfl_weeks_pull,
game_keys_pull,
reg_season,
post_season,
)
from Mom_WeeklyRankings_Export.cust_logging import log_print
from Mom_WeeklyRankings_Export.yahoo_data import league_season_data
from assests.assests import PRIVATE, TEAMS
def data_pipeline():
date = np.datetime64("today", "D")
# PATH = list(Path().cwd().glob("**/private.yaml"))
# if PATH == []:
# PATH = list(Path().cwd().parent.glob("**/private.yaml"))[0]
# else:
# PATH = PATH[0]
try:
with open(PRIVATE) as file:
credentials = yaml.load(file, Loader=yaml.SafeLoader)
CONSUMER_KEY = credentials["YFPY_CONSUMER_KEY"]
CONSUMER_SECRET = credentials["YFPY_CONSUMER_SECRET"]
DATE = np.datetime64(date, "D")
NFL_WEEKS = nfl_weeks_pull(PRIVATE)
START_OF_SEASON, SEASON = get_laborday(DATE)
GAME_KEYS = game_keys_pull(PRIVATE, TEAMS)
LEAGUE_ID = GAME_KEYS[GAME_KEYS["season"] == SEASON]["league_id"].values[0]
GAME_ID = GAME_KEYS[GAME_KEYS["season"] == SEASON]["game_id"].values[0]
NFL_WEEKS = NFL_WEEKS[NFL_WEEKS["game_id"] == GAME_ID]
MAX_WEEK = NFL_WEEKS["week"].max() - 1
END_OF_SEASON = NFL_WEEKS["week_end"][NFL_WEEKS["week"] == MAX_WEEK].values[0]
try:
NFL_WEEK = NFL_WEEKS[["week", "week_start", "week_end"]][
(NFL_WEEKS["week_end"] >= DATE) & (NFL_WEEKS["week_start"] <= DATE)
]
CURRENT_WEEK = NFL_WEEK["week"].values[0]
PREVIOUS_WEEK = CURRENT_WEEK - 1
WEEK_START = NFL_WEEK["week_start"].values[0]
WEEK_END = NFL_WEEK["week_end"].values[0]
except:
NFL_WEEK = DataFrame()
except Exception as e:
log_print(
error=e,
module_="app.py",
today=PRIVATE,
credentials="Credential File",
at_line="16",
)
league = league_season_data(
auth_dir=PRIVATE.parents[1],
league_id=LEAGUE_ID,
game_id=GAME_ID,
game_code="nfl",
offline=False,
all_output_as_json_str=False,
consumer_key=CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
browser_callback=True,
)
if DATE == START_OF_SEASON:
start = time()
league.all_game_keys()
league.all_nfl_weeks()
league.metadata()
league.settings()
league.teams()
end = time()
log_print(
success="Start Of Season",
module_="app.py",
date=DATE,
start_of_season=START_OF_SEASON,
end_of_season=END_OF_SEASON,
time_to_complete=(end - start) / 60,
)
elif DATE == END_OF_SEASON:
start = time()
league.all_game_keys()
league.all_nfl_weeks()
league.metadata()
league.settings()
end = time()
log_print(
success="End Of Season",
module_="app.py",
date=DATE,
start_of_season=START_OF_SEASON,
end_of_season=END_OF_SEASON,
time_to_complete=(end - start) / 60,
)
if not NFL_WEEK.empty:
if DATE == WEEK_START:
start = time()
league.teams()
league.matchups(nfl_week=PREVIOUS_WEEK)
league.weekly_points(nfl_week=PREVIOUS_WEEK)
end = time()
log_print(
success="Week finals",
module_="app.py",
date=DATE,
week_start=WEEK_START,
time_to_complete=(end - start) / 60,
)
elif DATE > WEEK_START and DATE <= WEEK_END:
start = time()
league.matchups(nfl_week=CURRENT_WEEK)
league.weekly_points(nfl_week=CURRENT_WEEK)
end = time()
log_print(
success="Mid-Week Pull",
module_="app.py",
date=DATE,
week_start=WEEK_START,
week_end=WEEK_END,
time_to_complete=(end - start) / 60,
)
reg_season(GAME_ID, PRIVATE)
post_season(GAME_ID, PRIVATE)
if __name__ == "__main__":
data_pipeline()