aboutsummaryrefslogtreecommitdiff
path: root/chess-stats.py
diff options
context:
space:
mode:
authorJJ <nicetry@noemail.com>2025-03-21 13:50:06 +0000
committerJJ <nicetry@noemail.com>2025-03-21 13:50:06 +0000
commita35f85b60051b3bd4a1fe056758d4df760ef7453 (patch)
tree68f3e7c56aa789e6e2c822c37d63ee8eca358f07 /chess-stats.py
first commit
Diffstat (limited to 'chess-stats.py')
-rwxr-xr-xchess-stats.py40
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()