-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhockey.py
50 lines (40 loc) · 1.84 KB
/
hockey.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
import pytz
from datetime import datetime
pst = pytz.timezone('America/Los_Angeles')
def game_search(games, game_count, teams_req):
games_req = []
counter = 0
while counter < game_count:
home_team = games[counter]['teams']['home']['team']['name']
away_team = games[counter]['teams']['away']['team']['name']
if [i for i in teams_req if i.lower() in home_team.lower() or i.lower() in away_team.lower()]:
games_req.append(counter)
counter += 1
return games_req
def scores(games, game_count, games_req):
counter = 0
msg = ""
while counter < game_count:
if counter in games_req:
game_status = games[counter]['status']['detailedState']
home_team = games[counter]['teams']['home']['team']['name']
away_team = games[counter]['teams']['away']['team']['name']
home_score = games[counter]['teams']['home']['score']
away_score = games[counter]['teams']['away']['score']
msg += f'*{away_team} @ {home_team}*\n'
#Scheduled
if game_status == "Scheduled":
game_time = datetime.strptime(games[counter]['gameDate'], "%Y-%m-%dT%H:%M:%S%z").astimezone(pst).time().strftime("%-I:%M %p")
msg += f'{game_status}: {game_time} PT\n'
#In Progress
elif game_status == "In Progress":
game_period = games[counter]['linescore']['currentPeriodOrdinal']
msg += f'{game_status} ({game_period} Period): {away_score}-{home_score}\n'
#Postponed
elif game_status == "Postponed":
msg += f'{game_status}\n'
#"In Progress - Critical", "Pre-Game, Final"
else:
msg += f'{game_status}: {away_score}-{home_score}\n'
counter += 1
return msg