initial commit: first working version
This commit is contained in:
commit
3832aecf95
1 changed files with 102 additions and 0 deletions
102
get_sheet.py
Normal file
102
get_sheet.py
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import csv
|
||||||
|
|
||||||
|
player_mapping = {
|
||||||
|
'RamaNoVarjan': 'Ramanujan',
|
||||||
|
'purplejoe2': 'PurpleJoe',
|
||||||
|
'PurpleJoeVar': 'PurpleJoe',
|
||||||
|
'yagami_blank': 'Yagami',
|
||||||
|
'yagami_black': 'Yagami',
|
||||||
|
'MarkusKahlsen': 'Markus',
|
||||||
|
'NoVarkusKahlsen': 'Markus',
|
||||||
|
'spring': 'spring',
|
||||||
|
'str8tsknacker': 'str8t',
|
||||||
|
'novarknacker': 'str8t',
|
||||||
|
'StKildaFan': 'Kilda',
|
||||||
|
'noarv': 'arv',
|
||||||
|
'arv': 'arv',
|
||||||
|
'ElenaDhynho': 'Elena',
|
||||||
|
'ElenaDhynh0': 'Elena',
|
||||||
|
'Elenanovar': 'Elena',
|
||||||
|
'TimeHoodie': 'Hoodie'
|
||||||
|
}
|
||||||
|
|
||||||
|
players_lower = [s.lower() for s in player_mapping.keys()]
|
||||||
|
player_cols = set()
|
||||||
|
for _, p in player_mapping.items():
|
||||||
|
player_cols.add(p)
|
||||||
|
|
||||||
|
class Entry():
|
||||||
|
def __init__(self, game_id, seed, score, players, bdr=0):
|
||||||
|
self.game_id = game_id
|
||||||
|
self.seed = seed
|
||||||
|
self.num_players = len(players)
|
||||||
|
self.won = 1 if score == 25 else 0
|
||||||
|
self.players = players
|
||||||
|
self.bdr = bdr
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_games(player: str):
|
||||||
|
r = requests.get('https://hanab.live/api/v1/history-full/{}'.format(player))
|
||||||
|
if r.status_code == 200:
|
||||||
|
return json.loads(r.text)
|
||||||
|
|
||||||
|
def collect_player_games():
|
||||||
|
global_games = {}
|
||||||
|
for player in player_mapping.keys():
|
||||||
|
print('Parsing games for player {}'.format(player))
|
||||||
|
games = get_player_games(player)
|
||||||
|
for game in games:
|
||||||
|
if game['options'].get('variantName', 'No Variant') != 'No Variant':
|
||||||
|
continue
|
||||||
|
|
||||||
|
game_id = game['id']
|
||||||
|
players = game['playerNames']
|
||||||
|
score = game['score']
|
||||||
|
seed = game['seed']
|
||||||
|
|
||||||
|
if len(players) not in [3,4,5]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
ok = True
|
||||||
|
for player in players:
|
||||||
|
if player.lower() not in players_lower:
|
||||||
|
ok = False
|
||||||
|
if ok:
|
||||||
|
global_games[game_id] = Entry(game_id, seed, score, players)
|
||||||
|
|
||||||
|
return global_games
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
games = collect_player_games()
|
||||||
|
streaks = {}
|
||||||
|
fieldnames = ['Replay Number', 'Seed Name', 'Player #', 'W/L(1/0)']
|
||||||
|
fieldnames += player_cols
|
||||||
|
|
||||||
|
with open('games.csv', 'w') as f:
|
||||||
|
f.writelines([','.join(fieldnames)])
|
||||||
|
|
||||||
|
with open('games.csv', 'w+', newline='') as f:
|
||||||
|
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
||||||
|
for _, entry in sorted(games.items()):
|
||||||
|
row = {
|
||||||
|
'Replay Number': entry.game_id,
|
||||||
|
'Seed Name': entry.seed,
|
||||||
|
'Player #': entry.num_players,
|
||||||
|
'W/L(1/0)': entry.won
|
||||||
|
}
|
||||||
|
for player in entry.players:
|
||||||
|
col = player_mapping[player]
|
||||||
|
if entry.won:
|
||||||
|
streak = streaks.get(col, 0)
|
||||||
|
streak += 1
|
||||||
|
streaks[col] = streak
|
||||||
|
row[col] = streak
|
||||||
|
else:
|
||||||
|
streaks[col] = 0
|
||||||
|
row[col] = 0
|
||||||
|
writer.writerow(row)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue