I used the code below to pull my games archives but it stopped working recently. I'm not very literate so I can't tell whether it's something with the Python library or the chess.com API. This is part of the error message I get:
Traceback (most recent call last):File "C:/Users/Bob/Desktop/chess.py", line 9, in <module>f = urllib.request.urlopen(archivesUrl)File "C:\Users\Bob\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 222, in urlopenreturn opener.open(url, data, timeout)
Here is the code I was using:
import urllibimport urllib.request
username = "BobChess" #changebaseUrl = "https://api.chess.com/pub/player/" + username + "/games/"archivesUrl = baseUrl + "archives"
#read the archives url and store in a listf = urllib.request.urlopen(archivesUrl)archives = f.read().decode("utf-8")archives = archives.replace("{\"archives\":[\"", "\",\"")archivesList = archives.split("\",\"" + baseUrl)archivesList[len(archivesList)-1] = archivesList[len(archivesList)-1].rstrip("\"]}")
#download all the archives#indent all lines below except first and last onesfor i in range(len(archivesList)-1):url = baseUrl + archivesList[i+1] + "/pgn"filename = archivesList[i+1].replace("/", "-")urllib.request.urlretrieve(url, "C:/Users/Bob/Desktop/Chess/" + filename + ".pgn") #changeprint(filename + ".pgn has been downloaded.")print ("All files have been downloaded.")