Created
September 6, 2023 15:48
-
-
Save mvrozanti/cdbd76b10e9845a253040c331e7e6151 to your computer and use it in GitHub Desktop.
Download chess.com games en masse
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
(async () => { | |
year=2023 | |
username = 'hikaru' | |
for(var month=1; month<=12; month++) { | |
let url = `https://api.chess.com/pub/player/${username}/games/${year}/${month}/pgn` | |
response = await fetch(url) | |
const bodyText = await response.text(); | |
const blob = new Blob([bodyText], { type: 'text/plain' }); | |
const a = document.createElement('a'); | |
a.style.display = 'none'; | |
document.body.appendChild(a); | |
url = window.URL.createObjectURL(blob); | |
a.href = url; | |
const monthFormatted = month < 10 ? `0${month}` : month; | |
a.download = `ChessCom_${username}_${year}${monthFormatted}.pgn`; | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
document.body.removeChild(a); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment