Skip to content

Instantly share code, notes, and snippets.

@qwqtoday
Created April 7, 2025 07:11
Show Gist options
  • Select an option

  • Save qwqtoday/2d4886b0ba8af7ae77ca680ae7b22b88 to your computer and use it in GitHub Desktop.

Select an option

Save qwqtoday/2d4886b0ba8af7ae77ca680ae7b22b88 to your computer and use it in GitHub Desktop.
super cool script to import 200 games to lichess
```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