Skip to content

Instantly share code, notes, and snippets.

@mvrozanti
Created September 6, 2023 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvrozanti/cdbd76b10e9845a253040c331e7e6151 to your computer and use it in GitHub Desktop.
Save mvrozanti/cdbd76b10e9845a253040c331e7e6151 to your computer and use it in GitHub Desktop.
Download chess.com games en masse
(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