-
Notifications
You must be signed in to change notification settings - Fork 2
/
teamRequests.py
123 lines (115 loc) · 4.39 KB
/
teamRequests.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
#external imports
import requests
#internal imports
import config
def basicInfo(msg, number):
#print("Basic team info")
for part in msg:
if part.isdigit():
team = part
break
else:
return False
r = requests.get(config.apiURL + "team/" + team,
headers=config.apiHeaders)
resp = r.json()
teamStr = ''
teamStr += str(resp[0]["team_number"]) + " - "
teamStr += resp[0]["team_name_short"] + ", "
teamStr += "Rookie Year: " + str(resp[0]["rookie_year"]) + ", "
teamStr += "Location: " + resp[0]["city"] + " " + resp[0]["state_prov"] + ", "
if resp[0]["website"] is not None:
teamStr += "Website: " + resp[0]["website"]
else:
teamStr = teamStr[:-2]
return [teamStr]
def events(msg, number):
#print("All events for the given season")
if 'events' in msg:
for part in msg:
if part.isdigit():
team = part
break
else:
return False
r = requests.get(config.apiURL + "team/" + team + "/events/"+config.seasonKey,
headers=config.apiHeaders)
# print(r.text)
advInfoString = "Events - "
for i in r.json():
# print(r.json()[r.json().index(i)]["event_key"])
eventr = requests.get(config.apiURL + "event/" + r.json()[r.json().index(i)]["event_key"], headers=config.apiHeaders)
advInfoString += eventr.json()[0]["event_name"] + ", "
return [advInfoString[:-2]]
return False
def awards(msg, number):
print("All awards for the given season")
if 'awards' in msg:
for part in msg:
if part.isdigit():
team = part
break
else:
return False
r = requests.get(config.apiURL + "team/" + team + "/awards/" + config.seasonKey,
headers=config.apiHeaders)
advInfoString = ""
respList = []
prevevent_name = ""
firstRun = True
addFinal = False
loopCount = 0
for i in r.json():
loopCount += 1
print(r.json()[r.json().index(i)]["award_name"])
eventr = requests.get(config.apiURL + "event/" + r.json()[r.json().index(i)]["event_key"], headers=config.apiHeaders)
if prevevent_name != eventr.json()[0]["event_name"] and firstRun == False:
advInfoString += r.json()[r.json().index(i)]["award_name"] + " @ " + prevevent_name
respList.append(advInfoString)
advInfoString = ""
prevevent_name = eventr.json()[0]["event_name"]
addFinal = False
else:
firstRun = False
advInfoString += r.json()[r.json().index(i)]["award_name"] + ", "
prevevent_name = eventr.json()[0]["event_name"]
addFinal = True
# advInfoString += r.json()[r.json().index(i)]["award_name"] + " @ " + eventr.json()[0]["event_name"] + ", "
if addFinal == True:
advInfoString = advInfoString[:-2] + " @ " + prevevent_name
respList.append(advInfoString)
return respList
return False
def matchInfo(msg,number):
#print("Match breakdown by category")
if 'matchinfo' in msg:
return ["This command is currently a WIP"]
return False
def opr(msg, number):
#print("OPR per event")
if 'opr' in msg:
for part in msg:
if part.isdigit():
team = part
break
else:
return False
r = requests.get(config.apiURL + "team/" + team + "/results/" + config.seasonKey,
headers=config.apiHeaders)
resp = r.json()
OPRavg = 0
maxOPR = 0
for event in resp:
OPRavg += event["opr"]
if event["opr"] > maxOPR:
maxOPR = event["opr"]
OPRavg = OPRavg/len(resp)
print(OPRavg)
return[str("This teams average OPR for the current season is " + str(OPRavg)),str("This teams max OPR for the current season is " + str(maxOPR))]
else:
return False
def avgscore(msg, number):
print("Average team alliance scores")
if 'avgscore' in msg:
return ["This command is currently a WIP"]
return False