diff options
Diffstat (limited to 'chess-stats.py')
-rwxr-xr-x | chess-stats.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/chess-stats.py b/chess-stats.py new file mode 100755 index 0000000..19da4cd --- /dev/null +++ b/chess-stats.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import requests +import os +import json +import Constants + +key=Constants.KEY +url=Constants.URL +headers={"Authorization": f'Bearer {key}'} +outfile="chessdata.json" + +def main(): + new_arr=[] + res = requests.get(url, headers=headers) + text = res.text + json_data = json.loads(text) + + for d in json_data: + time_control = d.get("name") + scores = d.get("points") + + if time_control in ("Bullet","Blitz","Rapid"): + new_obj={} + new_obj["time_control"] = time_control + new_obj["data"] = [] + for score in scores: + month = score[1] = score[1] + 1 + score_obj = {'x': f'{score[0]}-{month}-{score[2]}', 'y': f'{score[3]}'} + new_obj["data"].append(score_obj) + new_arr.append(new_obj) + + + with open(outfile, "w") as f: + json.dump(new_arr, f) + + + +if __name__ == "__main__": + main() |