-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoccer.py
200 lines (188 loc) · 5.43 KB
/
soccer.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
#import soccer
#from soccer import main
import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse
import json
import re
from sopel.module import commands, example
import itertools
#from soccer import leagueids
#from soccer.exceptions import IncorrectParametersException, APIErrorException
#from soccer.writers import get_writer
BASE_URL = 'http://api.football-data.org/alpha/'
LIVE_URL = 'http://soccer-cli.appspot.com/'
#LEAGUE_IDS = leagueids.LEAGUE_IDS
#TEAM_NAMES = teamnames.team_names
LEAGUE_IDS = {
"BL": 430,
"BL2": 431,
"FL": 434 ,
"FL2": 435,
"EPL": 426,
"EL1": 428,
"ECH": 427,
"LLIGA": 436,
"SD": 437,
"SA": 438,
"PPL": 439,
"DED": 433,
"CL": 405
}
team_names = {
"null": "532",
"SWA": "72",
"TSG": "2",
"GUI": "538",
"CRY": "354",
"NAN": "543",
"VFB": "10",
"ACM": "98",
"PSG": "524",
"LOR": "525",
"EIB": "278",
"AVFC": "58",
"EMP": "445",
"ESP": "80",
"WBA": "74",
"LAC": "560",
"PAL": "114",
"LAZ": "110",
"SEV": "559",
"AFCB": "1044",
"ETI": "527",
"JUVE": "109",
"BMG": "18",
"LFC": "64",
"WHU": "563",
"EFFZEH": "1",
"SMC": "514",
"GCF": "83",
"SCB": "536",
"FCT": "586",
"FCA": "16",
"FCB": "81",
"M05": "15",
"HSV": "7",
"DAR": "55",
"SUN": "71",
"FCI": "31",
"OSC": "521",
"SGE": "19",
"BOR": "526",
"BSC": "9",
"ATM": "78",
"NUFC": "67",
"VCF": "94",
"VALL": "87",
"THFC": "73",
"FCG": "82",
"BIL": "77",
"TOU": "511",
"AFC": "57",
"ROM": "100",
"OLY": "523",
"SASS": "471",
"B04": "3",
"H96": "8",
"Watfordfc": "346",
"SVW": "12",
"MON": "518",
"EFC": "62",
"FIO": "99",
"LCFC": "338",
"WOB": "11",
"MAR": "516",
"VIG": "558",
"REN": "529",
"Int": "108",
"NIC": "522",
"S04": "6",
"CFC": "61",
"MAL": "84",
"NCFC": "68",
"BVB": "4",
"REI": "547",
"MAD": "86",
"LUD": "88",
"MUFC": "66",
"MCFC": "65",
"SCFC": "70",
"VAL": "95",
"SFC": "340",
"SSC": "113",
"RSS": "92",
"BM": "5",
}
@commands('soccerlive')
def soccerlive(bot,trigger):
scores=json.loads(urllib.request.urlopen(LIVE_URL).read().decode())
if len(scores["games"]) == 0:
bot.say("No live action currently")
return
scoressorted=sorted(scores["games"],key=lambda x:x["league"])
for league,games in itertools.groupby(scoressorted,key=lambda x: x["league"]):
bot.say(league)
for game in games:
if 'result' in game:
bot.say(game["result"]["homeTeamName"]+"\t"+str(game["result"]["goalsHomeTeam"])+" vs "+str(game["result"]["goalsAwayTeam"])+" "+game["result"]["awayTeamName"])
else:
bot.say(game["homeTeamName"]+"\tvs \t"+game["awayTeamName"])
#else:
# bot.say("There was problem getting live scores")
@commands('soccerteams')
def soccerteams(bot,trigger):
list_team_codes(bot)
@commands('soccertable\s([A-Z]+[0-9]?)')
def soccertable(bot,trigger):
leagueid=LEAGUE_IDS[trigger.group(2)]
table=json.loads(urllib.request.urlopen(BASE_URL+"soccerseasons/"+str(leagueid)+"/leagueTable").read().decode())
clubnamelength=""
for team in table["standing"]:
if len(clubnamelength)<len(team["teamName"]):
clubnamelength=team["teamName"]
print(clubnamelength+" "+str(len(clubnamelength)))
clubnamelength=re.sub('.',' ',clubnamelength)
bot.say("POS\tCLUB"+clubnamelength[0:len(clubnamelength)-4]+"\tPLAYED\tGOAL DIFF\tPOINTS")
for team in table["standing"]:
print(team["teamName"]+" "+str(len(clubnamelength)-len(team["teamName"])))
bot.say(str(team["position"])+"\t"+str(team["teamName"])+clubnamelength[0:len(clubnamelength)-len(team["teamName"])]+"\t"+str(team["playedGames"])+"\t"+str(team["goalDifference"])+"\t"+str(team["points"]))
def list_team_codes(bot):
"""List team names in alphabetical order of team ID."""
teamcodes = sorted(TEAM_NAMES.keys())
here = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(here, "teamcodes.json")) as jfile:
data = json.load(jfile)
for code in teamcodes:
for key, value in data.iteritems():
if value == code:
bot.say(u"{0}: {1}".format(value, key))
break
'''
@commandss('soccer\s([A-z])+')
def soccercom(bot,trigger):
"""A CLI for live and past football scores from various football leagues"""
try:
writer = main.get_writer(output_format, output_file)
if listcodes:
main.list_team_codes()
return
if live:
main.get_live_scores(writer, use12hour)
return
if standings:
if not league:
raise IncorrectParametersException('Please specify a league. '
'Example --standings --league=EPL')
main.get_standings(league, writer)
return
if team:
if lookup:
main.map_team_id(team)
return
if players:
main.get_team_players(team, writer)
return
else:
main.get_team_scores(team, time, writer, upcoming, use12hour)
return
main.get_league_scores(league, time, writer, upcoming, use12hour)'''