aboutsummaryrefslogtreecommitdiff
path: root/chess-stats.py
blob: 19da4cd232cd234cf2d723f43fc1791d9e2335be (plain)
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
#!/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()