From 5cf3b61aada4ec2ee46060ab21166a123bb85e10 Mon Sep 17 00:00:00 2001 From: mez Date: Sun, 27 Apr 2025 10:04:16 +0100 Subject: [PATCH] move to here --- .gitignore | 2 ++ build.sh | 3 ++ generaterecords.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .gitignore create mode 100755 build.sh create mode 100644 generaterecords.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..06301f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/* +token.py \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..6876325 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +python3 generaterecords.py +rclone copy build prazevps:/var/www/tre/public/trackers/records/ -P diff --git a/generaterecords.py b/generaterecords.py new file mode 100644 index 0000000..1701213 --- /dev/null +++ b/generaterecords.py @@ -0,0 +1,72 @@ +import discogs_client,re,time,token +d = discogs_client.Client("Python/1.0",user_token=token.discogstoken) + +user = d.user("pilpaotr") + +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()