Commit 63ecac56 authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

change approach to be less fragile

parent 7e5bed53
......@@ -15,7 +15,7 @@ reSummary = re.compile('^\s*(.*)\*\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA
'([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+([0-9a-fA-F]+)\s+MG\-on.*$',re.MULTILINE)
oldGames=[]
newGames=[]
games=[]
recentlySaid=[]
lastData = ""
currentGames={}
......@@ -88,43 +88,42 @@ async def on_ready():
@tasks.loop(seconds=15.0)
async def status_task():
global oldGames, newGames, cnt, currentGames, recentlySaid
global oldGames, games, cnt, currentGames, recentlySaid
data = requests.get("https://www.managames.com/tennis/online/TE4_ServerList.php?Poll=1")
# if cnt==0:
# info = parse_server_poll('0 10E1 "POLAND vs TennisStar" B180D41 12C 6AC 96 "" "6/3 4/6 7/6" 510 2 46 617DAC94 * 1 0 0 34 1ED48 0 MG-on'.replace('\n',' '))
# else:
info = parse_server_poll(data.text.replace('\n',' '))
newGames = [{k:v for (k,v) in x.items() if k!= 'score'} for x in info['games']]
newGames = [x for x in newGames if sorted([str(y) for y in x.values()]) not in oldGames]
# newGames = [{k:v for (k,v) in x.items() if k!= 'score'} for x in info['games']]
games = info['games']
# newGames = [x for x in newGames if x['score'] == '...' and sorted([str(y) for y in x.values()]) not in oldGames]
out=[]
nix=[]
for game in info['games']:
if "..." not in game['score'] and " -- " not in game['score'] and game['name'] in currentGames.keys():
out += [f"The {game['name']} game is finished. The final score was {game['score']}."]
del currentGames[game['name']]
# for game in info['games']:
# if "..." not in game['score'] and " -- " not in game['score'] and game['name'] in currentGames.keys():
# out += [f"The {game['name']} game is finished. The final score was {game['score']}."]
# pprint.pprint(currentGames)
# del currentGames[game['name']]
for ongoing in currentGames.keys():
if ongoing not in [x['name'] for x in info['games']]:
if ongoing not in [x['name'] for x in games]:
out += [f"The {ongoing} game is finished. Final score: {currentGames[ongoing]['score']}"]
nix += [ongoing]
for xin in nix:
del currentGames[xin]
if len(newGames)>0 or len(out)>0:
for game in newGames:
if game['ip']=='0' and ' -- ' in game['score']:
if ' vs ' not in game['name']:
continue
else:
if len(games)>0 or len(out)>0:
for game in games:
s = ""
if game['ip']=='0' and ' vs ' in game['name']:
if game['name'] not in currentGames.keys():
s = f"The {game['name']} match has begun."
filt = tuple(filter(lambda x: x['name'] == game['name'], info['games']))[0]
# currentGames[game['name']] = [v for (k,v) if k==game['name'] in x.items() for x in info['games'] ][0]
currentGames[game['name']] = filt
currentGames[game['name']] = game
else:
s = f"{game['name']} (elo: {game['elo']}, rep: {game['reputation']}%) wants to play a {game['game_info']['nb_set']}-set match."
if len(game['tagline'])>0:
s += f" Comment: {game['tagline']}"
if s not in recentlySaid:
if s != "" and s not in recentlySaid:
out += [s]
recentlySaid.append(s)
if len(recentlySaid) > 5:
......@@ -133,12 +132,13 @@ async def status_task():
if len(out) > 0:
pprint.pprint(out)
await ch.send("\n".join(out))
oldGames = [sorted([str(y) for y in x.values()]) for x in newGames]
oldGames = [sorted([str(y) for y in x.values()]) for x in games]
# oldGames += newGames
# oldGames =
# if (len(oldGames)>10):
# oldGames=oldGames[-10:]
else:
if len(games) == 0:
recentlySaid = []
cnt+=1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment