Compare commits

...

10 commits

7 changed files with 340 additions and 10 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
ficheader.html
albums.py
prompts.html
prompts.org
__pycache__/*

View file

@ -1,6 +1,7 @@
* Python utilities for personal and fannish purposes
- =ao3scrape.py= downloads all an authors works from AO3 (notes [[https://tobli.dreamwidth.org/45337.html][here]])
- =ao3scrape.py= downloads all an authors works from AO3
- =cellopractice.py= selects some exercises from Walter Menglers /Fit in 15 Minutes/, according to the authors recommendations
- =ffyuletide.py= checks which Final Fantasy fandoms are Yuletide-eligible
- =peterson.py= questions everything
- =promptscrape.py= scrapes Dreamwidth writing challenge communities for prompts
- =randomline.py= returns a random line from a file

62
ffyuletide.py Normal file
View file

@ -0,0 +1,62 @@
import re, requests, time
from bs4 import BeautifulSoup
# grab subtags of "final fantasy series"
series = "https://archiveofourown.org/tags/Final%20Fantasy%20Series"
seriespage = requests.get(series)
seriessoup = BeautifulSoup(seriespage.content,"html.parser")
fandoms = seriessoup.find(class_="sub").find("ul",{ "class" : "tree" }).findAll("li", recursive=False)
# open search page with filters applied
filterpage = "https://archiveofourown.org/works?work_search%5Bsort_column%5D=revised_at&work_search%5Bother_tag_names%5D=&work_search%5Bexcluded_tag_names%5D=&work_search%5Bcrossover%5D=&work_search%5Bcomplete%5D=T&work_search%5Bwords_from%5D=1000&work_search%5Bwords_to%5D=&work_search%5Bdate_from%5D=&work_search%5Bdate_to%5D=&work_search%5Bquery%5D=&work_search%5Blanguage_id%5D=en&commit=Sort+and+Filter&tag_id="
eligible = []
ineligible = []
with requests.Session() as s:
loginpage = s.get("https://archiveofourown.org/users/login")
loginsoup = BeautifulSoup(loginpage.content,"html.parser")
token = (loginsoup.find('form', class_='new_user')
.find('input', attrs={'name': 'authenticity_token'})
.get('value'))
payload = {'user[login]': "translinkni",
'user[password]': "fakeapi",
'user[remember_me]': '1',
'authenticity_token': token
}
post = s.post("https://archiveofourown.org/users/login",data=payload)
for fandom in fandoms:
time.sleep(3)
tagurl = (str(fandom.find("a")["href"]))[6:]
tagname = str(fandom.find(class_="tag").text)
print("Checking " + tagname + " (" + str(fandoms.index(fandom) + 1) + " of " + str(len(fandoms)) + ")")
tagpage = s.get(filterpage + tagurl)
tagsoup = BeautifulSoup(tagpage.content,"html.parser")
# get the number
heading = (tagsoup.find("h2",class_="heading")).text
stripone = re.sub("\n","",heading)
striptwo = re.sub(" Work.*","",stripone)
stripthree = re.sub(".* of ","",striptwo)
stripfour = re.sub(",","",stripthree)
workcount = int(stripfour)
# if number < 1000, add to eligible list
fandomdict = {"name":tagname,"count":workcount}
if workcount < 1000:
eligible.append(fandomdict)
else:
ineligible.append(fandomdict)
eligible = sorted(eligible,key=lambda d: d["count"],reverse=True)
ineligible = sorted(ineligible,key=lambda d: d["count"],reverse=True)
print("\nCurrently eligible:\n")
for fandom in eligible:
print(fandom["name"] + " (" + str(fandom["count"]) + ")")
print("\nIneligible:\n")
for fandom in ineligible:
print(fandom["name"] + " (" + str(fandom["count"]) + ")")

19
otd.py Normal file
View file

@ -0,0 +1,19 @@
import datetime,os
year = int(datetime.datetime.strftime(datetime.datetime.today(),"%Y"))
monthstring = datetime.datetime.strftime(datetime.datetime.today(),"%m")
datestring = datetime.datetime.strftime(datetime.datetime.today(),"%d")
fileplace = "/home/mdd/Documents/drive/org/journal/"
thisyear = year
while year > 1993:
year -= 1
target = fileplace + str(year) + "/" + monthstring + "/" + str(year) + "-" + monthstring + "-" + datestring + ".org"
if os.path.exists(target):
if year < thisyear -1:
print("Press enter to continue")
input()
print(open(target,"r").read())

47
prompts.css Normal file
View file

@ -0,0 +1,47 @@
html {
text-transform: lowercase;
color: #808080;
background-color: #d5d5ef;
/* opacity: 0.8; */
background-image: repeating-radial-gradient( circle at 0 0, transparent 0, #d5d5ef 28px ), repeating-linear-gradient( #cfcfe5, #cfcfe7 );
font-family: "Poppins", sans-serif;
}
a {
color: #999999;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
body {
margin: 0 auto;
max-width: 800px;
}
div.promptwrapper > div.promptcomm {
border: 1px solid #808080;
padding: 0 5px;
}
div.promptcomm:first-of-type {
border-radius: 5px 5px 0 0;
}
div.promptcomm:last-of-type {
border-radius: 0 0 5px 5px;
}
div.timestamp {
text-align: right;
}
.prompt {
font-weight: 700;
}
.notes {
color: #b3b3b3;
}

View file

@ -18,6 +18,8 @@ today = int(date.today().strftime("%d"))
month = str(date.today().strftime("%B"))
monthstring = ".*" + month + ".*"
prompts = []
try:
cent = "https://100words.dreamwidth.org/tag/!prompt?style=light&tag=%21prompt"
centpage = requests.get(cent)
@ -33,6 +35,7 @@ try:
centtheprompt = centprompttext.find("strong")
print("100words (100 words): \033[1m" + centtheprompt.text.lower() + "\033[0m (" + centprompt + ")\n")
thefile.write("- [[" + centprompt + "][100words]] (100 words): *" + centtheprompt.text.lower() + "*\n")
prompts.append({"source":"100words","type":"comm","notes":"100 words","prompt":centtheprompt.text.lower(),"url":centprompt})
except:
pass
@ -88,6 +91,7 @@ try:
adstrippable = adstrippable[1:]
print("anythingdrabble (100, 200, 300, 400, or 500 words): \033[1m" + adstrippable.lower() + "\033[0m (" + adprompt + ")\n")
thefile.write("- [[" + adprompt + "][anythingdrabble]] (100, 200, 300, 400, or 500 words): *" + adstrippable.lower() + "*\n")
prompts.append({"source":"anythingdrabble","type":"comm","notes":"100, 200, 300, 400, or 500 words","prompt":adstrippable.lower(),"url":adprompt})
except:
pass
@ -95,7 +99,7 @@ try:
dove = "https://dove-drabbles.dreamwidth.org/?style=light"
dovepage = requests.get(dove)
dovesoup = BeautifulSoup(dovepage.content, "html.parser")
doveprompts = dovesoup.find_all("h3", string=lambda text: "prompt post" in text.lower())
doveprompts = dovesoup.find_all("h3", string=lambda text: "prompt" in text.lower())
dovesubsoup = BeautifulSoup(str(doveprompts[0]), "html.parser")
doveurl = dovesubsoup.find("a")
doveprompt = (doveurl["href"])
@ -106,6 +110,7 @@ try:
dovetheprompt = doveprompttext.find("i")
print("dove-drabbles (any): \033[1m" + dovetheprompt.text.lower() + "\033[0m (" + doveprompt + ")\n")
thefile.write("- [[" + doveprompt + "][dove-drabbles]] (any): *" + dovetheprompt.text.lower() + "*\n")
prompts.append({"source":"dove-drabbles","type":"comm","notes":"any length","prompt":dovetheprompt.text.lower(),"url":doveprompt})
except:
pass
@ -123,10 +128,16 @@ try:
zonepromptpage = s.get(zonepromptnew)
zonepromptsoup = BeautifulSoup(zonepromptpage.content, "html.parser")
zoneprompttext = zonepromptsoup.find(class_="entry-content")
zonetheprompt = zoneprompttext.find("strong")
zonetheprompt = zoneprompttext.find("div")
print("drabble-zone (100 or 200 words): \033[1m" + zonetheprompt.text.lower() + "\033[0m (" + zoneprompt + ")\n")
thefile.write("- [[" + zoneprompt + "][drabble-zone]] (100 or 200 words): *" + zonetheprompt.text.lower() + "*\n")
prompts.append({"source":"drabble-zone","type":"comm","notes":"100 or 200 words","prompt":zonetheprompt.text.lower(),"url":zoneprompt})
except:
pass
try:
with requests.Session() as s:
response = s.post(login_url , data)
emotion = "https://emotion100.dreamwidth.org/tag/*modpost?style=light&tag=%2Amodpost"
emotionpage = s.get(emotion)
emotionsoup = BeautifulSoup(emotionpage.content, "html.parser")
@ -141,6 +152,7 @@ try:
emotiontheprompt = emotionprompttext.find_all("span")[-1]
print("emotion100 (100 words or a multiple of 100): \033[1m" + emotiontheprompt.text.lower() + "\033[0m (" + emotionprompt + ")\n")
thefile.write("- [[" + emotionprompt + "][emotion100]] (100 words or a multiple of 100): *" + emotiontheprompt.text.lower() + "*\n")
prompts.append({"source":"emotion100","type":"comm","notes":"100 words or a multiple of 100","prompt":emotiontheprompt.text.lower(),"url":emotionprompt})
except:
pass
@ -184,6 +196,7 @@ try:
ffaformat = "; ".join(ffacentnew)
print("fail-fandomanon (any): \033[1m" + ffaformat.lower() + "\033[0m (" + ffaprompt + ")\n")
thefile.write("- [[" + ffaprompt + "][fail-fandomanon]] (any): *" + ffaformat.lower() + "*\n")
prompts.append({"source":"fail-fandomanon","type":"comm","notes":"any length","prompt":ffacentnew,"url":ffaprompt})
except:
pass
@ -206,6 +219,7 @@ try:
fandomtheprompt = fandomprompttext.find("td")
print("fandomweekly (any, competitive): \033[1m" + fandomtheprompt.text.lower() + "\033[0m (" + fandomprompt + ")\n")
thefile.write("- [[" + fandomprompt + "][fandomweekly]] (any, competitive): *" + fandomtheprompt.text.lower() + "*\n")
prompts.append({"source":"fandomweekly","type":"comm","notes":"any length, competitive","prompt":fandomtheprompt.text.lower(),"url":fandomprompt})
except:
pass
@ -224,6 +238,28 @@ try:
flashtheprompt = flashprompttext.find("center")
print("fan-flashworks (any, cant post elsewhere until round is closed): \033[1m" + flashtheprompt.text.lower() + "\033[0m (" + flashprompt + ")\n")
thefile.write("- [[" + flashprompt + "][fan-flashworks]] (any, cant post elsewhere until round is closed): *" + flashtheprompt.text.lower() + "*\n")
prompts.append({"source":"fan-flashworks","type":"comm","notes":"any length, cant post elsewhere until round is closed","prompt":flashtheprompt.text.lower(),"url":flashprompt})
except:
pass
try:
with requests.Session() as s:
response = s.post(login_url , data)
fsf = "https://femslashfete.dreamwidth.org/tag/admin?style=light&tag=admin"
fsfpage = s.get(fsf)
fsfsoup = BeautifulSoup(fsfpage.content, "html.parser")
fsfprompts = fsfsoup.find_all("h3", string=lambda text: "challenge" in text.lower())
fsfsubsoup = BeautifulSoup(str(fsfprompts[0]), "html.parser")
fsfurl = fsfsubsoup.find("a")
fsfprompt = (fsfurl["href"])
fsfpromptnew = (fsfurl["href"] + "?style=light")
fsfpromptpage = s.get(fsfpromptnew)
fsfpromptsoup = BeautifulSoup(fsfpromptpage.content, "html.parser")
fsfprompttext = fsfpromptsoup.find(class_="entry-content")
fsftheprompt = fsfprompttext.find("b")
print("femslashfete (at least 100 words, must be femslash): \033[1m" + fsftheprompt.text.lower() + "\033[0m (" + fsfprompt + ")\n")
thefile.write("- [[" + fsfprompt + "][femslashfete]] (at least 100 words, must be femslash): *" + fsftheprompt.text.lower() + "*\n")
prompts.append({"source":"femslashfete","type":"comm","notes":"at least 100 words, must be femslash","prompt":fsftheprompt.text.lower(),"url":fsfprompt})
except:
pass
@ -264,6 +300,7 @@ try:
fffclittleprompttext = fffclittlepromptsoup.find("h3")
print("fffc little special (at least 100 words): \033[1m" + fffclittleprompttext.text.lower() + "\033[0m (" + fffclittleprompt + ")\n")
thefile.write("- [[" + fffclittleprompt + "][fffc little special]] (at least 100 words): *" + fffclittleprompttext.text.lower() + "*\n")
prompts.append({"source":"fffc","type":"comm","notes":"at least 100 words","prompt":fffclittleprompttext.text.lower(),"url":fffclittleprompt,"challenge":"little special"})
fffcmadnessprompts = fffcsoup.find_all("h3", string=lambda text: "froday madness" in text.lower())
fffcmadnesssubsoup = BeautifulSoup(str(fffcmadnessprompts[0]), "html.parser")
fffcmadnessurl = fffcmadnesssubsoup.find("a")
@ -275,6 +312,7 @@ try:
fffcmadnesstheprompt = fffcmadnessprompttext.find("b")
print("fffc madness (at least 2000 words): \033[1m" + fffcmadnesstheprompt.text.lower() + "\033[0m (" + fffcmadnessprompt + ")\n")
thefile.write("- [[" + fffcmadnessprompt + "][fffc madness]] (at least 2000 words): *" + fffcmadnesstheprompt.text.lower() + "*\n")
prompts.append({"source":"fffc","type":"comm","notes":"at least 2000 words","prompt":fffcmadnesstheprompt.text.lower(),"url":fffcmadnessprompt,"challenge":"froday madness"})
fffcmonthlyprompts = fffcsoup.find_all("h3", string=re.compile(monthstring))
fffcmonthlysubsoup = BeautifulSoup(str(fffcmonthlyprompts[0]), "html.parser")
fffcmonthlyurl = fffcmonthlysubsoup.find("a")
@ -285,6 +323,7 @@ try:
fffcmonthlyprompttext = fffcmonthlypromptsoup.find("h3")
print("fffc monthly special (usually at least 500 words): \033[1m" + fffcmonthlyprompttext.text.lower() + "\033[0m (" + fffcmonthlyprompt + ")\n")
thefile.write("- [[" + fffcmonthlyprompt + "][fffc monthly special]] (usually at least 500 words): *" + fffcmonthlyprompttext.text.lower() + "*\n")
prompts.append({"source":"fffc","type":"comm","notes":"usually at least 500 words","prompt":fffcmonthlyprompttext.text.lower(),"url":fffcmonthlyprompt,"challenge":"monthly challenge"})
fffcregularprompts = fffcsoup.find_all("h3", string=lambda text: "regular challenge" in text.lower())
fffcregularsubsoup = BeautifulSoup(str(fffcregularprompts[0]), "html.parser")
fffcregularurl = fffcregularsubsoup.find("a")
@ -296,6 +335,7 @@ try:
fffcregulartheprompt = fffcregularprompttext.find("b")
print("fffc regular challenge (at least 100 words): \033[1m" + fffcregulartheprompt.text.lower() + "\033[0m (" + fffcregularprompt + ")\n")
thefile.write("- [[" + fffcregularprompt + "][fffc regular challenge]] (at least 100 words): *" + fffcregulartheprompt.text.lower() + "*\n")
prompts.append({"source":"fffc","type":"comm","notes":"at least 100 words","prompt":fffcregulartheprompt.text.lower(),"url":fffcregularprompt,"challenge":"regular challenge"})
except:
pass
@ -314,6 +354,7 @@ try:
ficlettheprompt = ficletprompttext.find("a")
print("ficlet-zone (any): \033[1m" + ficlettheprompt.text.lower() + "\033[0m (" + ficletprompt + ")\n")
thefile.write("- [[" + ficletprompt + "][ficlet-zone]] (any): *" + ficlettheprompt.text.lower() + "*\n")
prompts.append({"source":"ficlet-zone","type":"comm","notes":"any length","prompt":ficlettheprompt.text.lower(),"url":ficletprompt})
except:
pass
@ -340,6 +381,7 @@ try:
hourlypromptthishour = str(hourlypromptmedian[0])[5:-5]
print("hourlyprompts (any): \033[1m" + hourlypromptthishour.lower() + "\033[0m (" + hourlyprompt + ")\n")
thefile.write("- [[" + hourlyprompt + "][hourlyprompts]] (any): *" + hourlypromptthishour.lower() + "*\n")
prompts.append({"source":"hourlyprompts","type":"comm","notes":"any length","prompt":hourlypromptthishour.lower(),"url":hourlyprompt})
except:
pass
@ -381,6 +423,7 @@ if themonth != 4 and themonth != 8 and themonth != 12:
ssbingofinal = "; ".join(ssbingoclean).lower()
print("sweet and short bingo (up to 500 words, separate or combined): \033[1m" + ssbingofinal + "\033[0m (" + ssbingoprompt + ")\n")
thefile.write("- [[" + ssbingoprompt + "][sweet and short bingo]] (up to 500 words, separate or combined): *" + ssbingofinal + "*\n")
prompts.append({"source":"sweetandshort","type":"comm","notes":"up to 500 words, separate or combined","prompt":ssbingoclean,"url":ssbingoprompt,"challenge":"bingo"})
except:
pass
@ -398,18 +441,18 @@ if themonth != 4 and themonth != 8 and themonth != 12:
ssquickypromptnew = (ssquickyurl["href"])
ssquickypromptpage = requests.get(ssquickypromptnew)
ssquickypromptsoup = BeautifulSoup(ssquickypromptpage.content, "html.parser")
promptcatch = ".*New Prompts Here"
# ssquickytheprompt = ssquickypromptsoup.find_all("h4",string = re.compile(promptcatch))
ssquickytheprompt = ssquickypromptsoup.find_all(class_="comment")
ssquickycomments = []
for comment in ssquickytheprompt:
if re.search("New Prompts Here",str(comment)):
if re.search("new prompts here",str(comment),re.IGNORECASE):
commenttext = re.findall(r"<div class=\"comment-content\".*?</div>",str(comment))
commentprompt = re.sub("<.*?>","",str(commenttext))
commentprompt = re.sub("<.*?>","",str(commenttext)).replace("\\'","'")
ssquickycomments.append(str(commentprompt)[2:-2])
ssquickycomments = ssquickycomments[1:]
ssquickycprompt = "; ".join(ssquickycomments)
print("sweet and short comment quicky (up to 100 words): \033[1m" + ssquickycprompt.lower() + "\033[0m (" + ssquickyprompt + ")\n")
thefile.write("- [[" + ssquickyprompt + "][sweet and short comment quicky]] (up to 100 words): *" + ssquickycprompt.lower() + "*\n")
prompts.append({"source":"sweetandshort","type":"comm","notes":"up to 100 words","prompt":ssquickycomments,"url":ssquickyprompt,"challenge":"comment quicky"})
elif alternate == "picture":
sspicture = "https://sweetandshort.dreamwidth.org/tag/!new+challenge,challenge:+picture+prompt+fun?mode=and&style=light&tag=%21new+challenge,challenge:+picture+prompt+fun&mode=and"
sspicturepage = requests.get(sspicture)
@ -425,6 +468,7 @@ if themonth != 4 and themonth != 8 and themonth != 12:
sspictureprompttext = sspicturepromptsoup.find("h3")
print("sweet and short picture prompts (up to 300 words): \033[1m" + sspictureprompttext.text.lower() + "\033[0m (" + sspictureprompt + ")\n")
thefile.write("- [[" + sspictureprompt + "][sweet and short picture prompts]] (up to 300 words): *" + sspictureprompttext.text.lower() + "*\n")
prompts.append({"source":"sweetandshort","type":"comm","notes":"up to 300 words","prompt":sspictureprompttext.text.lower(),"url":sspictureprompt,"challenge":"picture prompt fun"})
except:
pass
@ -447,6 +491,7 @@ if themonth != 4 and themonth != 8 and themonth != 12:
ssmonthlypromptfinal = str(ssmonthlypromptstripthree)[2:-2]
print("sweet and short monthly prompts (up to 500 words based on at least 10 prompts): \033[1m" + ssmonthlypromptfinal + "\033[0m (" + ssmonthlyprompt + ")\n")
thefile.write("- [[" + ssmonthlyprompt + "][sweet and short monthly prompts]] (up to 500 words based on at least 10 prompts): *" + ssmonthlypromptfinal + "*\n")
prompts.append({"source":"sweetandshort","type":"comm","notes":"up to 500 words based on at least 10 prompts","prompt":ssmonthlypromptfinal,"url":ssmonthlyprompt,"challenge":"monthly prompt"})
except:
pass
@ -468,7 +513,7 @@ if themonth != 4 and themonth != 8 and themonth != 12:
ssonepromptfinal = re.sub("2. ","; ",ssonepromptstriptwo)
print("sweet and short one sentence (up to 500 words, use one or both lines as the start and/or end): \033[1m" + ssonepromptfinal + "\033[0m (" + ssoneprompt + ")\n")
thefile.write("- [[" + ssoneprompt + "][sweet and short one sentence]] (up to 500 words, use one or both lines as the start and/or end): *" + ssonepromptfinal + "*\n")
prompts.append({"source":"sweetandshort","type":"comm","notes":"up to 500 words, use one or both lines as the start and/or end","prompt":ssonepromptfinal,"url":ssoneprompt,"challenge":"only one"})
except:
pass
@ -487,5 +532,30 @@ try:
vocabtheprompt = vocabprompttext.find("strong")
print("vocab-drabbles (50500 words): \033[1m" + vocabtheprompt.text.lower() + "\033[0m (" + vocabprompt + ")\n")
thefile.write("- [[" + vocabprompt + "][vocab-drabbles]] (50500 words): *" + vocabtheprompt.text.lower() + "*\n")
prompts.append({"source":"vocab-drabbles","type":"comm","notes":"50500 words","prompt":vocabtheprompt.text.lower(),"url":vocabprompt})
except:
pass
if os.path.exists("prompts.html"):
os.remove("prompts.html")
htmlfile = open("prompts.html", "a")
htmlfile.write("<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <link rel=\"stylesheet\" href=\"prompts.css\">\n <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n <link href=\"https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap\" rel=\"stylesheet\">\n <meta name=\"theme-color\" content=\"#d5d5ef\">\n <title>Multifandom prompt communities on DW</title>\n </head>\n <body>\n <h1>Multifandom prompt communities on DW</h1>\n <div class=\"promptwrapper\">\n")
for prompt in prompts:
htmlfile.write(" <div class=\"promptcomm\"><p><span style=\"white-space: nowrap;\" class=\"ljuser\"><a href=\"https://" + prompt["source"] + ".dreamwidth.org/profile\"><img src=\"https://www.dreamwidth.org/img/silk/identity/community.png\" alt=\"[community profile]\" width=\"17\" height=\"17\" style=\"border: 0; padding-right: 1px;\" /></a><a href=\"https://" + prompt["source"] + ".dreamwidth.org/\"><b>" + prompt["source"].replace("-","_") + "</b></a></span>")
try:
if prompt["challenge"]:
htmlfile.write(" " + prompt["challenge"])
except:
pass
if type(prompt["prompt"]) == list:
htmlfile.write(": <a href=\"" + prompt["url"] + "\">prompt post</a> <span class=\"notes\">(" + prompt["notes"] + ")</span></p>\n <ul>\n")
for theprompt in prompt["prompt"]:
htmlfile.write(" <li><span class=\"prompt\">" + theprompt + "</span></li>\n")
htmlfile.write(" </ul>")
else:
htmlfile.write(": <a href=\"" + prompt["url"] + "\"><span class=\"prompt\">" + prompt["prompt"] + "</span></a> <span class=\"notes\">(" + prompt["notes"] + ")</span></p>")
htmlfile.write("</div>\n")
htmlfile.write(" </div>\n <div class=\"timestamp\"><p>Generated " + datetime.now().strftime("%H:%M (UK time), %-d %B %Y") + "</p></div>\n </body>\n</html>")
htmlfile.close()

130
scrobble.py Normal file
View file

@ -0,0 +1,130 @@
import pylast,random,re,sys,time,requests
import albums
network = pylast.LastFMNetwork(api_key=albums.apikey, api_secret=albums.apisecret, username="litrovers", password_hash=pylast.md5(albums.pw)) # https://input.sh/scrobbling-live-sets-into-last-fm-using-python/
thealbums = sorted(albums.albums,key=lambda d: d["name"])
# albums = sorted(albums,key=lambda d: d["artist"])
def countdown(t): # https://stackoverflow.com/a/25189629
while t:
mins, secs = divmod(t,60)
timeformat = '{:02d}:{:02d}'.format(mins,secs)
print("> " + timeformat,end='\r')
time.sleep(1)
t -= 1
def scrobble(thealbum):
for album in thealbums:
if thealbum == album["code"]:
i = 0
for tracklist in album["tracks"]:
i += 1
for item in tracklist:
if " :: " in item:
theartist = re.sub(" :: .*","",item)
thetrack = re.sub(".* :: ","",item)
else:
theartist = album["artist"]
thetrack = item
if theartist == "noscrob":
print("Skipped " + thetrack)
else:
if tracklist[item] > 29:
last_api_call = network.scrobble(theartist,thetrack,int(time.time()))
try:
requests.post("https://ple.praze.net/api/v1/pleroma/scrobble",data = {"artist":theartist,"length":int(time.time()),"title":thetrack},auth = ("tre",albums.plepass))
except:
pass
print("Scrobbled " + thetrack)
else:
print("Skipped " + thetrack)
last_api_call = network.update_now_playing(theartist,thetrack,duration=tracklist[item])
countdown(tracklist[item])
if i < len(album["tracks"]):
input("Press enter after changing side")
def query_yes_no(question, default="yes"): # https://code.activestate.com/recipes/577058/
"""Ask a yes/no question via raw_input() and return their answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
The "answer" return value is one of "yes" or "no".
"""
valid = {"yes":"yes", "y":"yes", "ye":"yes",
"no":"no", "n":"no"}
if default == None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while 1:
sys.stdout.write(question + prompt)
choice = input().lower()
if default is not None and choice == '':
return default
elif choice in valid.keys():
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' "\
"(or 'y' or 'n').\n")
def selectFromDict(options, name): # https://stackoverflow.com/a/64536882
index = 0
indexValidList = []
print('Select an ' + name + ':')
for optionName in options:
index = index + 1
indexValidList.extend([options[optionName]])
print(str(index) + ') ' + optionName)
inputValid = False
while not inputValid:
inputRaw = input(name + ': ')
inputNo = int(inputRaw) - 1
if inputNo > -1 and inputNo < len(indexValidList):
selected = indexValidList[inputNo]
# print('Selected ' + name + ': ' + selected)
inputValid = True
break
else:
print('Please select a valid ' + name + ' number')
return selected
def choosealbum():
randomer = query_yes_no("Pick an album for me?","no")
if randomer == "yes":
revision = "yes"
while revision == "yes":
chosen = random.choice(thealbums)
thechosen = chosen["code"]
try:
print(chosen["album artist"] + ": " + chosen["name"])
except:
print(chosen["artist"] + ": " + chosen["name"])
revision = query_yes_no("Roll again?","no")
else:
process = False
while process == False:
firstletter = input("Type the first letter of the album name\n")
letteralbums = {}
for album in thealbums:
process = True
if album["name"][0].lower() == str(firstletter):
try:
letteralbums[album["name"] + " (" + album["album artist"] + ")"] = album["code"]
except:
letteralbums[album["name"] + " (" + album["artist"] + ")"] = album["code"]
if len(letteralbums) == 0:
process = False
print("No albums found")
thechosen = selectFromDict(letteralbums, "album")
scrobble(thechosen)
if __name__ == "__main__":
choosealbum()