import discogs_client,re,time,variables d = discogs_client.Client("Python/1.0",user_token=variables.discogstoken) user = d.user(variables.discogsuser) try: if sys.argv[1] == "local": local = True else: local = False except: local = False if variables.trackrecords == True: records = [] thenumber = 1 maxno = len(user.collection_folders[0].releases) def typography(thestring): return re.sub(" / ","/",re.sub(" \(.*\)","",re.sub(" - "," – ",re.sub(" "," ",re.sub("\.\.\."," …",re.sub("'","’",re.sub(" = .*","",thestring))))))) print("Fetching records from Discogs") for item in user.collection_folders[0].releases: print("Fetching " + str(thenumber) + " of " + str(maxno)) theitem = {} theitem["artist"] = typography(item.release.artists[0].name) theitem["title"] = typography(item.release.title) try: if "LP" in item.release.formats[0]["descriptions"] or "12\"" in item.release.formats[0]["descriptions"]: theitem["format"] = "large" else: theitem["format"] = "small" except: theitem["format"] = "small" try: theitem["img"] = item.release.images[0]["uri"] except: pass records.append(theitem) thenumber += 1 time.sleep(1) # only allowed 1 request per second records = sorted(records, key=lambda d: d["title"]) records = sorted(records, key=lambda d: d["artist"]) smalls = [] larges = [] for record in records: if record["format"] == "large": larges.append(record) else: smalls.append(record) def recordwrite(record): recordstring = "
\n \n
\n

" + record["artist"] + "

" + record["title"] + "

\n
\n
\n" return recordstring writefile = open("recordbuild/index.html","w") writefile.write("\n\n \n \n \n Record collection\n \n \n \n

Record collection

\n
\n") for record in smalls: writefile.write(recordwrite(record)) for record in larges: writefile.write(recordwrite(record)) writefile.write("
\n

Generic disc icons by popo2021 and Dinosoft Labs on Flaticon.

\n \n\n") writefile.close()