17
17
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
"""
19
19
20
+ from __future__ import annotations
21
+
20
22
import requests
21
23
24
+ from typing import Any , NamedTuple
25
+
26
+ JSON = dict [str , Any ]
27
+
22
28
FOOTBALL_URL = "http://site.api.espn.com/apis/site/v2/sports/football/college-football/teams/pitt"
23
29
MENS_BASKETBALL_URL = "http://site.api.espn.com/apis/site/v2/sports/basketball/mens-college-basketball/teams/pittsburgh"
24
30
25
31
32
+ class GameInfo (NamedTuple ):
33
+ timestamp : str | None = None
34
+ opponent : dict [str , str ] | None = None
35
+ home_away : str | None = None
36
+ location : dict [str , str ] | None = None
37
+ status : str | None = None
38
+
39
+
26
40
def get_mens_basketball_record () -> str :
27
41
"""returns the current record of the men's basketball team"""
28
42
basketball_data = _get_mens_basketball_data ()
29
43
30
44
try :
31
- record_summary = basketball_data ["team" ]["record" ]["items" ][0 ]["summary" ]
32
-
45
+ record_summary : str = basketball_data ["team" ]["record" ]["items" ][0 ]["summary" ]
33
46
except KeyError :
34
47
record_summary = "There's no record right now."
35
48
36
49
return record_summary
37
50
38
51
39
- def get_next_mens_basketball_game () -> dict :
52
+ def get_next_mens_basketball_game () -> GameInfo :
40
53
"""returns a dict containing details of the next scheduled men's basketball game."""
41
54
basketball_data = _get_mens_basketball_data ()
42
55
next_game = None
@@ -55,30 +68,29 @@ def get_next_mens_basketball_game() -> dict:
55
68
else :
56
69
opponent = next_game ["competitions" ][0 ]["competitors" ][1 ]
57
70
homeaway = next_game ["competitions" ][0 ]["competitors" ][1 ]["homeAway" ]
58
- return {
59
- " timestamp" : next_game ["date" ],
60
- " opponent" : {
71
+ return GameInfo (
72
+ timestamp = next_game ["date" ],
73
+ opponent = {
61
74
"id" : opponent ["team" ]["id" ],
62
75
"school" : opponent ["team" ]["nickname" ],
63
76
"name" : opponent ["team" ]["displayName" ],
64
77
},
65
- " home_away" : homeaway ,
66
- " location" : {
78
+ home_away = homeaway ,
79
+ location = {
67
80
"full_name" : next_game ["competitions" ][0 ]["venue" ]["fullName" ],
68
81
"address" : next_game ["competitions" ][0 ]["venue" ]["address" ],
69
82
},
70
- " status" : status ,
71
- }
83
+ status = status ,
84
+ )
72
85
except IndexError :
73
86
# IndexError occurs when a next game on the schedule is not present
74
- return { " status" : " NO_GAME_SCHEDULED"}
87
+ return GameInfo ( status = " NO_GAME_SCHEDULED")
75
88
76
89
77
90
def get_mens_basketball_standings () -> str :
78
91
"""returns a string describing the placement of the men's basketball team. eg: '14th in ACC'"""
79
92
basketball_data = _get_mens_basketball_data ()
80
-
81
- return_value = basketball_data ["team" ]["standingSummary" ]
93
+ return_value : str = basketball_data ["team" ]["standingSummary" ]
82
94
return return_value
83
95
84
96
@@ -87,15 +99,14 @@ def get_football_record() -> str:
87
99
football_data = _get_football_data ()
88
100
89
101
try :
90
- record_summary = football_data ["team" ]["record" ]["items" ][0 ]["summary" ]
91
-
102
+ record_summary : str = football_data ["team" ]["record" ]["items" ][0 ]["summary" ]
92
103
except KeyError :
93
104
record_summary = "There's no record right now."
94
105
95
106
return record_summary
96
107
97
108
98
- def get_next_football_game () -> dict :
109
+ def get_next_football_game () -> GameInfo :
99
110
football_data = _get_football_data ()
100
111
next_game = None
101
112
try :
@@ -113,36 +124,37 @@ def get_next_football_game() -> dict:
113
124
else :
114
125
opponent = next_game ["competitions" ][0 ]["competitors" ][0 ]
115
126
homeaway = next_game ["competitions" ][0 ]["competitors" ][1 ]["homeAway" ]
116
- return {
117
- " timestamp" : next_game ["date" ],
118
- " opponent" : {
127
+ return GameInfo (
128
+ timestamp = next_game ["date" ],
129
+ opponent = {
119
130
"id" : opponent ["team" ]["id" ],
120
131
"school" : opponent ["team" ]["nickname" ],
121
132
"name" : opponent ["team" ]["displayName" ],
122
133
},
123
- " home_away" : homeaway ,
124
- " location" : {
134
+ home_away = homeaway ,
135
+ location = {
125
136
"full_name" : next_game ["competitions" ][0 ]["venue" ]["fullName" ],
126
137
"address" : next_game ["competitions" ][0 ]["venue" ]["address" ],
127
138
},
128
- " status" : status ,
129
- }
139
+ status = status ,
140
+ )
130
141
except IndexError :
131
142
# IndexError occurs when a next game on the schedule is not present
132
- return { " status" : " NO_GAME_SCHEDULED"}
143
+ return GameInfo ( status = " NO_GAME_SCHEDULED")
133
144
134
145
135
146
def get_football_standings () -> str :
136
147
"""returns a string describing the placement of the football team. eg: '14th in ACC'"""
137
148
football_data = _get_football_data ()
138
-
139
- return_value = football_data ["team" ]["standingSummary" ]
149
+ return_value : str = football_data ["team" ]["standingSummary" ]
140
150
return return_value
141
151
142
152
143
- def _get_mens_basketball_data () -> dict :
144
- return requests .get (MENS_BASKETBALL_URL ).json ()
153
+ def _get_mens_basketball_data () -> JSON :
154
+ json_data : JSON = requests .get (MENS_BASKETBALL_URL ).json ()
155
+ return json_data
145
156
146
157
147
- def _get_football_data () -> dict :
148
- return requests .get (FOOTBALL_URL ).json ()
158
+ def _get_football_data () -> JSON :
159
+ json_data : JSON = requests .get (FOOTBALL_URL ).json ()
160
+ return json_data
0 commit comments