yuletide-vn.py
· 1.1 KiB · Python
Raw
import re,requests
from bs4 import BeautifulSoup
maxhours = 45
with open("tagset.html","r") as tagset:
tagsoup = BeautifulSoup(tagset,"html.parser")
fandoms = tagsoup.find_all("li",class_="fandom")
vns = []
for fandom in fandoms:
title = fandom.find("h4")
if "Visual Novel" in title.text:
thetitle = re.sub(" \(.*Visual Novel.*\)\n.*\n.*","",re.sub(".* \| ","",title.text.strip()))
vns.append(thetitle)
final = []
for vn in vns:
x = requests.post("https://api.vndb.org/kana/vn",json={"filters":["and",["lang","=","en"],["search","=",vn],["olang","=","ja"],["or",["platform","=","ps4"],["platform","=","ps5"],["platform","=","swi"]]],"fields":"title, length_minutes, id"})
try:
for result in x.json()["results"]:
if result["length_minutes"] < (maxhours * 60):
final.append(result["title"] + ": https://vndb.org/" + result["id"] + " (" + vn + ")")
except requests.exceptions.JSONDecodeError:
pass
final = sorted(list(dict.fromkeys(final)))
for vn in final:
print(vn)
| 1 | import re,requests |
| 2 | from bs4 import BeautifulSoup |
| 3 | |
| 4 | maxhours = 45 |
| 5 | |
| 6 | with open("tagset.html","r") as tagset: |
| 7 | tagsoup = BeautifulSoup(tagset,"html.parser") |
| 8 | fandoms = tagsoup.find_all("li",class_="fandom") |
| 9 | vns = [] |
| 10 | for fandom in fandoms: |
| 11 | title = fandom.find("h4") |
| 12 | if "Visual Novel" in title.text: |
| 13 | thetitle = re.sub(" \(.*Visual Novel.*\)\n.*\n.*","",re.sub(".* \| ","",title.text.strip())) |
| 14 | vns.append(thetitle) |
| 15 | |
| 16 | final = [] |
| 17 | |
| 18 | for vn in vns: |
| 19 | x = requests.post("https://api.vndb.org/kana/vn",json={"filters":["and",["lang","=","en"],["search","=",vn],["olang","=","ja"],["or",["platform","=","ps4"],["platform","=","ps5"],["platform","=","swi"]]],"fields":"title, length_minutes, id"}) |
| 20 | try: |
| 21 | for result in x.json()["results"]: |
| 22 | if result["length_minutes"] < (maxhours * 60): |
| 23 | final.append(result["title"] + ": https://vndb.org/" + result["id"] + " (" + vn + ")") |
| 24 | except requests.exceptions.JSONDecodeError: |
| 25 | pass |
| 26 | |
| 27 | final = sorted(list(dict.fromkeys(final))) |
| 28 | for vn in final: |
| 29 | print(vn) |