-
Notifications
You must be signed in to change notification settings - Fork 0
/
thepythonalliance.py
211 lines (183 loc) · 9.89 KB
/
thepythonalliance.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import requests
import datetime
import sys
now = datetime.datetime.now()
#This whole project was based on some code by @gersteinj.
#Thanks for the initial code!
initials = 'TF'
github = "https://github.com/MC42/"
teamToHighlight = str("1257") #Enter your own team here!
baseURL = 'http://www.thebluealliance.com/api/v2/'
header = {'X-TBA-App-Id': 'frc1257:thepythonalliance:beta'} #Yay, version strings....
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class tba:
def get_team(self):
team = raw_input('Please enter a team:')
myRequest = (baseURL + 'team/frc' + str(team))
response = requests.get(myRequest, headers=header)
jsonified = response.json()
print(bcolors.HEADER + 'Team Information for FRC' + str(team)+ bcolors.ENDC)
if jsonified['location'] != None:
if jsonified['nickname'] != None:
print('Team Nickname: \t'+ bcolors.OKGREEN + jsonified['nickname']+ bcolors.ENDC )
if jsonified['name'] != None:
print('Team Full Name: '+ bcolors.OKGREEN + jsonified['name']+ bcolors.ENDC )
print('Team Number: \t' + bcolors.OKGREEN + str(jsonified['team_number']) + bcolors.ENDC )
if jsonified['website'] != None:
print('Website: \t'+ bcolors.OKGREEN + jsonified['website']+ bcolors.ENDC )
print('Rookie Year: \t'+ bcolors.OKGREEN + str(jsonified['rookie_year'])+ bcolors.ENDC )
print('\t' + bcolors.OKBLUE + 'Location Data:' + bcolors.ENDC)
if jsonified['locality'] != None:
print('Locality: \t' + bcolors.OKGREEN + jsonified['locality']+ bcolors.ENDC )
if jsonified['location'] != None:
print('Location: \t' + bcolors.OKGREEN + jsonified['location']+ bcolors.ENDC )
if jsonified['country_name'] != None:
print('Country: \t' + bcolors.OKGREEN + jsonified['country_name']+ bcolors.ENDC )
if (jsonified['location'] == None) and (jsonified['website'] == None):
print('\nThere is no information avalible for Team ' + bcolors.HEADER + str(team) + bcolors.ENDC + '\nThis team has likely since been dissolved.')
if (team == teamToHighlight):
print(bcolors.WARNING + 'You\'re looking at your own team. Or you\'re debugging...' + bcolors.ENDC)
def get_events(self, year):
myRequest = (baseURL + 'events/' + str(year))
response = requests.get(myRequest, headers=header)
jsonified = response.json()
print(bcolors.HEADER + bcolors.BOLD + bcolors.UNDERLINE + 'All Events for the ' + str(year)+ ' Season' + bcolors.ENDC)
#print(jsonified)
for event in jsonified:
print('Event Name:\t\t' + bcolors.OKGREEN + event['name'] + bcolors.ENDC)
print('Event Code:\t\t' + bcolors.BOLD + event['event_code'].upper() + bcolors.ENDC)
if str(event['official']).upper() == 'FALSE':
print('Official FIRST Event?\t' + bcolors.WARNING + str(event['official']) + bcolors.ENDC)
elif str(event['official']).upper() == 'TRUE':
print('Official FIRST Event?\t' + bcolors.OKGREEN + str(event['official']) + bcolors.ENDC)
if event['short_name'] != None:
print('Simple Name:\t\t' + bcolors.OKGREEN + event['short_name'] + bcolors.ENDC)
print('Location:\t\t' + bcolors.OKGREEN + event['location'] + bcolors.ENDC)
print('End Date:\t\t' + bcolors.OKBLUE + event['end_date'] + bcolors.ENDC)
if event['alliances'] != []:
print('\t' + bcolors.BOLD + 'Alliances:' + bcolors.ENDC) #idk
for alli in event['alliances']:
print('')
for picks in alli['picks']:
print(picks.upper())
print('--------------------------')
t = raw_input('') #Just to hold the location until they hit enter.
def get_all_team(self):
page = raw_input('Enter a page number please: ')
myRequest = (baseURL + 'teams/' + str(page))
response = requests.get(myRequest, headers=header)
jsonified = response.json()
print(bcolors.HEADER + 'Team Information : Page ' + str(page)+ bcolors.ENDC)
for team in jsonified:
#print(team) #BEDUG
print(bcolors.HEADER + 'Team Information for FRC' + str(team['team_number'])+ bcolors.ENDC)
if team['location'] != None:
if team['nickname'] != None:
print('Team Nickname: \t'+ bcolors.OKGREEN + team['nickname']+ bcolors.ENDC )
if team['name'] != None:
print('Team Full Name: '+ bcolors.OKGREEN + team['name']+ bcolors.ENDC )
print('Team Number: \t' + bcolors.OKGREEN + str(team['team_number']) + bcolors.ENDC )
if team['website'] != None:
print('Website: \t'+ bcolors.OKGREEN + team['website']+ bcolors.ENDC )
print('Rookie Year: \t'+ bcolors.OKGREEN + str(team['rookie_year'])+ bcolors.ENDC )
print('\t' + bcolors.OKBLUE + 'Location Data:' + bcolors.ENDC)
if team['locality'] != None:
print('Locality: \t' + bcolors.OKGREEN + team['locality']+ bcolors.ENDC )
if team['location'] != None:
print('Location: \t' + bcolors.OKGREEN + team['location']+ bcolors.ENDC )
if team['country_name'] != None:
print('Country: \t' + bcolors.OKGREEN + team['country_name']+ bcolors.ENDC )
print('\n--------------------------\n')
if (team['location'] == None) and (team['website'] == None):
print('\nThere is no information avalible for Team ' + bcolors.HEADER + str(team['team_number']) + bcolors.ENDC + '\nThis team has likely since been dissolved.')
def get_districts(self):
myRequest = (baseURL + 'districts/' + str(now.year))
response = requests.get(myRequest, headers=header)
district_json = response.json()
#print(district_json)
print(bcolors.HEADER + 'FIRST Districts (' + str(now.year)+ bcolors.ENDC + ')')
for districts in district_json:
print(bcolors.OKGREEN + districts['key'].upper() + bcolors.ENDC + '\t\t' + bcolors.OKBLUE + districts['name'] + bcolors.ENDC)
def get_distrank(self):
district=raw_input('Please enter a district code (Hint, can be gotten with \'d\' command): ')
myRequest = (baseURL + 'district/' + district.lower() + '/' + str(now.year) + '/rankings')
response = requests.get(myRequest, headers=header)
district_json = response.json()
#print(district_json)
print(bcolors.HEADER + district.upper() + ' District Rankings (' + str(now.year)+ bcolors.ENDC + ')')
for districts in district_json:
if ((districts['team_key'][3:]) == teamToHighlight): ## Whoops, easter egg?
print(bcolors.OKBLUE + districts['team_key'].upper() + bcolors.ENDC + '\t\t' + bcolors.RED + str(districts['rank']) + bcolors.ENDC + '\tPoints: ' + bcolors.WARNING + str(districts['point_total']) + bcolors.ENDC + '\tName: ' + bcolors.OKGREEN + tba.get_team_name(districts['team_key'][3:] ) + bcolors.ENDC)
else:
print(districts['team_key'].upper() + '\t\t' + bcolors.RED + str(districts['rank']) + bcolors.ENDC + '\tPoints: ' + bcolors.WARNING + str(districts['point_total']) + bcolors.ENDC + '\tName: ' + bcolors.OKGREEN + tba.get_team_name(districts['team_key'][3:] ) + bcolors.ENDC)
def get_team_name(self, team_no):
myRequest = (baseURL + 'team/frc' + str(team_no))
response = requests.get(myRequest, headers=header)
jsonified = response.json()
return jsonified['nickname']
def get_rookie_year(self, team_no):
myRequest = (baseURL + 'team/frc' + str(team_no))
response = requests.get(myRequest, headers=header)
jsonified = response.json()
return jsonified['rookie_year']
def get_event_info(self):
event_code = raw_input('Enter event code.')
myRequest = (baseURL + 'event/' + str(now.year) + str(event_code))
response = requests.get(myRequest, headers=header)
jsonified = response.json()
print(jsonified)
print('Event Name:\t\t' + bcolors.OKGREEN + jsonified['name'] + bcolors.ENDC)
print('Event Code:\t\t' + bcolors.BOLD + jsonified['event_code'].upper() + bcolors.ENDC)
if str(jsonified['official']).upper() == 'FALSE':
print('Official FIRST Event?\t' + bcolors.WARNING + str(jsonified['official']) + bcolors.ENDC)
elif str(jsonified['official']).upper() == 'TRUE':
print('Official FIRST Event?\t' + bcolors.OKGREEN + str(jsonified['official']) + bcolors.ENDC)
if jsonified['short_name'] != None:
print('Simple Name:\t\t' + bcolors.OKGREEN + jsonified['short_name'] + bcolors.ENDC)
print('Location:\t\t' + bcolors.OKGREEN + jsonified['location'] + bcolors.ENDC)
print('End Date:\t\t' + bcolors.OKBLUE + jsonified['end_date'] + bcolors.ENDC)
if jsonified['alliances'] != []:
print('\t' + bcolors.BOLD + 'Alliances:' + bcolors.ENDC) #idk
for alli in jsonified['alliances']:
print('')
for picks in alli['picks']:
print(picks.upper())
def help(self):
print('Please enter a section of the site to load:')
print('\'e\' or \'events\' for a list of all events this season.')
print('\'ev\' or \'event\' for information on a single event.')
print('\'t\' or \'team\' for a single team\'s information.')
print('\'a\' or \'all\' for a list of all teams. (by page number on TBA)')
print('\'d\' or \'district\' for a list of all current FIRST Districts & Codes')
print('\'dr\' or \'distrank\' for district rankings for a specific district.')
print('\'?\' or \'help\' for this page.')
print(bcolors.OKBLUE + ' ________ ___ __ __ ___ _____ \n/_ __/ / ___ / _ \__ __/ /_/ / ___ ___ / _ | / / (_)__ ____ _______ \n / / / _ \/ -_) / ___/ // / __/ _ \/ _ \/ _ \ / __ |/ / / / _ `/ _ \/ __/ -_)\n/_/ /_//_/\__/ /_/ \_, /\__/_//_/\___/_//_/ /_/ |_/_/_/_/\_,_/_//_/\__/\__/ \n /___/ ' + bcolors.ENDC)
tba = tba()
tba.help()
command = raw_input('')
command = command.split(' ')
if ((command[0] is 'e') or (command[0] == 'events')):
tba.get_events(now.year)
elif ((command[0] is 't') or (command[0] == 'team')):
tba.get_team()
elif ((command[0] is 'a') or (command[0] == 'all')):
tba.get_all_team()
elif ((command[0] is 'd') or (command[0] == 'district')):
tba.get_districts()
elif ((command[0] == 'dr') or (command[0] == 'dist')):
tba.get_distrank()
elif ((command[0] == 'ev') or (command[0] == 'event')):
tba.get_event_info()
elif ((command[0] == '?') or (command[0] == 'help')):
tba.help()
else:
print('Please enter a valid command.')
#That's all folks!