-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcfm_advance.py
186 lines (160 loc) · 7.65 KB
/
cfm_advance.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import cfm_schedule
import response_objects
import constants
def advance_to_preseason(db_root):
'''Set internal league counter to week 1 of preseason
Arguments:
db_root {Object} -- Reference to root of Firebase database
Returns:
List -- User vs. User games for week 1 of preseason
'''
schedule = []
db_root.update({'league': response_objects.pre_dict})
schedule.append('Preseason Week 1 Schedule')
user_games = cfm_schedule.get_user_games(db_root, 'pre', '1')
if (user_games[0] == constants.USER_GAME_ERROR):
return user_games
else:
return schedule + user_games
def advance_to_reg(db_root):
'''Set internal league counter to week 1 of the regular season
Arguments:
db_root {Object} -- Reference to root of Firebase database
Returns:
List -- User vs. User games for week 1 of the regular season
'''
schedule = []
db_root.update({'league': response_objects.reg_dict})
schedule.append('Regular Season Week 1 Schedule')
user_games = cfm_schedule.get_user_games(db_root, 'reg', '1')
if (user_games[0] == constants.USER_GAME_ERROR):
return user_games
else:
return schedule + user_games
def advance_to_playoffs(db_root):
'''Set internal league counter to wildcard week of the playoffs
Arguments:
db_root {Object} -- Reference to root of Firebase database
Returns:
List -- User vs. User games for wildcard week
'''
schedule = []
db_root.update({'league': response_objects.playoffs_dict})
schedule.append('Wildcard Schedule')
user_games = cfm_schedule.get_user_games(db_root, 'reg', '18')
if (user_games[0] == constants.USER_GAME_ERROR):
return user_games
else:
return schedule + user_games
def advance(db_root, msg, func_index):
print('Advance keyword found')
schedule = []
if(len(msg) > func_index + 1) and (msg[func_index + 1].lower() == 'pre'):
try:
print('Advancing to the beginning of preseason')
schedule = advance_to_preseason(db_root)
return '\n'.join(schedule)
except Exception as e:
print(e)
return constants.UNEXPECTED_ERR_MSG
elif(len(msg) > func_index + 1) and (msg[func_index + 1].lower() == 'reg'):
try:
print('Advancing to the beginning of regular season')
schedule = advance_to_reg(db_root)
return '\n'.join(schedule)
except Exception as e:
print(e)
return constants.UNEXPECTED_ERR_MSG
elif(len(msg) > func_index + 1) and (msg[func_index + 1].lower() == 'playoffs'):
try:
print('Advancing to the beginning of playoffs')
schedule = advance_to_playoffs(db_root)
return '\n'.join(schedule)
except Exception as e:
print(e)
return constants.UNEXPECTED_ERR_MSG
elif(len(msg) > func_index + 1) and (msg[func_index + 1].lower() == 'offseason'):
try:
print('Advancing to the beginning of offseason')
db_root.update({'league': response_objects.offseason_dict})
return 'Offseason Stage 1: Resign Players'
except Exception as e:
print(e)
return constants.UNEXPECTED_ERR_MSG
else:
try:
league_snapshot = db_root.child('league').get()
week_type = league_snapshot['weekType']
week_number = league_snapshot['weekNumber']
if week_type == 'pre':
week_number += 1
if week_number < 5:
week_dict = {'weekNumber': week_number, 'weekType': 'pre'}
db_root.update({'league': week_dict})
schedule.append(f'Preason Week {week_number} Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'pre', str(week_number))
return '\n'.join(schedule)
else:
db_root.update({'league': response_objects.reg_dict})
schedule.append(f'Regular Season Week 1 Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', '1')
return '\n'.join(schedule)
elif week_type == 'reg':
week_number += 1
if week_number < 18:
week_dict = {'weekNumber': week_number, 'weekType': 'reg'}
db_root.update({'league': week_dict})
schedule.append(f'Regular Season Week {week_number} Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', str(week_number))
return '\n'.join(schedule)
else:
db_root.update({'league': response_objects.playoffs_dict})
schedule.append('Wildcard Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', '18')
return '\n'.join(schedule)
elif week_type == 'playoffs':
week_number += 1
if week_number == 21:
return 'Pro Bowl Week'
elif week_number == 18:
week_dict = {'weekNumber': week_number, 'weekType': 'playoffs'}
db_root.update({'league': week_dict})
schedule.append('Wildcard Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', str(week_number))
return '\n'.join(schedule)
elif week_number == 19:
week_dict = {'weekNumber': week_number, 'weekType': 'playoffs'}
db_root.update({'league': week_dict})
schedule.append('Divisional Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', str(week_number))
return '\n'.join(schedule)
elif week_number == 20:
week_dict = {'weekNumber': week_number, 'weekType': 'playoffs'}
db_root.update({'league': week_dict})
schedule.append('Conference Championship Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', str(week_number))
return '\n'.join(schedule)
elif week_number == 22:
week_dict = {'weekNumber': week_number, 'weekType': 'playoffs'}
db_root.update({'league': week_dict})
schedule.append('Super Bowl Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'reg', str(week_number))
return '\n'.join(schedule)
else:
db_root.update({'league': response_objects.offseason_dict})
return 'Offseason Stage 1: Resign Players'
else:
week_number += 1
if week_number < 30:
week_dict = {'weekNumber': week_number, 'weekType': 'offseason'}
db_root.update({'league': week_dict})
offseason_stage = week_number - 22
return f'Offseason Stage {offseason_stage}: {response_objects.offseason_stages[week_number-23]}'
else:
db_root.update({'league': response_objects.pre_dict})
schedule.append('Preseason Week 1 Schedule')
schedule = schedule + cfm_schedule.get_user_games(db_root, 'pre', '1')
return '\n'.join(schedule)
except Exception as e:
print(e)
return constants.UNEXPECTED_ERR_MSG