Created
April 7, 2025 07:11
-
-
Save qwqtoday/2d4886b0ba8af7ae77ca680ae7b22b88 to your computer and use it in GitHub Desktop.
super cool script to import 200 games to lichess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ```py | |
| import sys | |
| import chess.pgn | |
| import time | |
| pgn_file = open(sys.argv[1], "r") | |
| games = [] | |
| while True: | |
| game = chess.pgn.read_game(pgn_file) | |
| if not game: | |
| break | |
| games.append(game) | |
| print(games) | |
| import requests | |
| token = sys.argv[2] | |
| headers = {"Authorization": f"Bearer {token}"} | |
| for game in games: | |
| pgn = str(game) | |
| sleep_time = 10 | |
| while True: | |
| response = requests.post( | |
| "https://lichess.org/api/import", | |
| headers=headers, | |
| data={"pgn": pgn}, | |
| ) | |
| if response.status_code == 200: | |
| break | |
| time.sleep(sleep_time) | |
| sleep_time += 3 | |
| print(response.json()) # Check for errors | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment