Add RSS feeds for books and films
This commit is contained in:
parent
223fb2d88c
commit
f98fd67f5a
3 changed files with 150 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -4,5 +4,6 @@ build/games/*
|
||||||
!build/games/*.png
|
!build/games/*.png
|
||||||
secrets.py
|
secrets.py
|
||||||
build/places/*
|
build/places/*
|
||||||
!build/places/.gitkeep
|
|
||||||
placelist.py
|
placelist.py
|
||||||
|
build/books/*
|
||||||
|
build/films/*
|
148
generate.py
148
generate.py
|
@ -30,6 +30,11 @@ while year < int(thisyear) + 1:
|
||||||
places = []
|
places = []
|
||||||
placenames = []
|
placenames = []
|
||||||
|
|
||||||
|
books = []
|
||||||
|
bookids = []
|
||||||
|
|
||||||
|
films = []
|
||||||
|
|
||||||
games = []
|
games = []
|
||||||
gamenames = []
|
gamenames = []
|
||||||
holding = []
|
holding = []
|
||||||
|
@ -102,9 +107,79 @@ for file in concernedfiles:
|
||||||
games.remove(origgame)
|
games.remove(origgame)
|
||||||
games.insert(0,gamemerge)
|
games.insert(0,gamemerge)
|
||||||
holding.remove(gameupdate)
|
holding.remove(gameupdate)
|
||||||
|
if node.heading == "books":
|
||||||
|
for action in node.children:
|
||||||
|
if action.heading == "read":
|
||||||
|
for book in action.children:
|
||||||
|
bookid = re.sub(" and rated .*","",book.heading)
|
||||||
|
if bookid not in bookids:
|
||||||
|
status = "new"
|
||||||
|
bookids.append(bookid)
|
||||||
|
else:
|
||||||
|
status = "existing"
|
||||||
|
readdate = dateobj
|
||||||
|
if status == "new":
|
||||||
|
thedict = {"id":bookid,"readdates":[readdate],"progressdates":[],"obtaineddate":""}
|
||||||
|
books.append(thedict)
|
||||||
|
else:
|
||||||
|
twodict = {"id":bookid,"readdates":[readdate]}
|
||||||
|
for origbook in books:
|
||||||
|
if twodict["id"] == origbook["id"]:
|
||||||
|
origbook["readdates"].extend(twodict["readdates"])
|
||||||
|
if action.heading == "progress":
|
||||||
|
for book in action.children:
|
||||||
|
bookid = book.heading
|
||||||
|
if bookid not in bookids:
|
||||||
|
status = "new"
|
||||||
|
bookids.append(bookid)
|
||||||
|
else:
|
||||||
|
status = "existing"
|
||||||
|
progressdate = dateobj
|
||||||
|
if status == "new":
|
||||||
|
thedict = {"id":bookid,"readdates":[],"progressdates":[progressdate],"obtaineddate":""}
|
||||||
|
books.append(thedict)
|
||||||
|
else:
|
||||||
|
twodict = {"id":bookid,"progressdates":[progressdate]}
|
||||||
|
for origbook in books:
|
||||||
|
if twodict["id"] == origbook["id"]:
|
||||||
|
origbook["progressdates"].extend(twodict["progressdates"])
|
||||||
|
if action.heading == "obtained":
|
||||||
|
for book in action.children:
|
||||||
|
bookid = re.sub(" \(.*\)","",book.heading)
|
||||||
|
if bookid not in bookids:
|
||||||
|
status = "new"
|
||||||
|
bookids.append(bookid)
|
||||||
|
else:
|
||||||
|
status = "existing"
|
||||||
|
obtaineddate = dateobj
|
||||||
|
if status == "new":
|
||||||
|
thedict = {"id":bookid,"readdates":[],"progressdates":[],"obtaineddate":obtaineddate}
|
||||||
|
books.append(thedict)
|
||||||
|
else:
|
||||||
|
twodict = {"id":bookid,"obtaineddate":[obtaineddate]}
|
||||||
|
for origbook in books:
|
||||||
|
if twodict["id"] == origbook["id"]:
|
||||||
|
origbook["obtaineddate"] = twodict["obtaineddate"]
|
||||||
|
if node.heading == "films":
|
||||||
|
for action in node.children:
|
||||||
|
if action.heading == "watched":
|
||||||
|
for film in action.children:
|
||||||
|
filmid = re.sub(" and rated .*","",film.heading)
|
||||||
|
watchdate = dateobj
|
||||||
|
thedict = {"id":filmid,"watched":watchdate}
|
||||||
|
films.append(thedict)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
for book in books:
|
||||||
|
try:
|
||||||
|
book["title"] = (re.findall(" /.*/",book["id"])[0])[2:-1]
|
||||||
|
except:
|
||||||
|
book["title"] = (re.findall("/.*/",book["id"])[0])[1:-1]
|
||||||
|
book["author"] = re.sub(" /.*/","",book["id"])
|
||||||
|
if book["author"][0] == "/":
|
||||||
|
book["author"] = ""
|
||||||
|
|
||||||
for place in places:
|
for place in places:
|
||||||
place["dates"] = list(dict.fromkeys(place["dates"]))
|
place["dates"] = list(dict.fromkeys(place["dates"]))
|
||||||
|
|
||||||
|
@ -927,7 +1002,7 @@ def history():
|
||||||
else:
|
else:
|
||||||
filewrite.write(event["action"])
|
filewrite.write(event["action"])
|
||||||
filewrite.write("\"></div>\n </div>\n <div> " + event["name"] + "\n <span>(" + event["console"] + ")</span>\n </div>\n </div>\n </div>\n")
|
filewrite.write("\"></div>\n </div>\n <div> " + event["name"] + "\n <span>(" + event["console"] + ")</span>\n </div>\n </div>\n </div>\n")
|
||||||
feedwrite.write(" <item>\n <title>" + event["action"] + " " + event["name"] + " (" + event["console"] + ")</title>\n <pubDate>" + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 GMT</pubDate>\n <link>https://tre.praze.net/trackers/games/history</link>\n <guid isPermaLink=\"false\">" + event["action"] + "-" + event["name"].replace(" ","-") + "-" + event["console"] + "</guid>\n <description>" + event["action"] + " " + event["name"] + " (" + event["console"] + ")</description>\n </item>\n")
|
feedwrite.write(" <item>\n <title>" + event["action"] + " " + event["name"] + " (" + event["console"] + ")</title>\n <pubDate>" + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 GMT</pubDate>\n <link>https://tre.praze.net/trackers/games/history</link>\n <guid isPermaLink=\"false\">" + event["action"] + "-" + event["name"].replace(" ","-") + "-" + event["date"].strftime("%Y-%m-%d") + "</guid>\n <description>" + event["action"] + " " + event["name"] + " (" + event["console"] + ")</description>\n </item>\n")
|
||||||
checkdate = event["date"]
|
checkdate = event["date"]
|
||||||
theyear -= 1
|
theyear -= 1
|
||||||
|
|
||||||
|
@ -1028,3 +1103,74 @@ def history():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
history()
|
history()
|
||||||
|
|
||||||
|
def bookfeed():
|
||||||
|
if not os.path.isdir("build/books"):
|
||||||
|
os.mkdir("build/books")
|
||||||
|
if os.path.exists("build/books/feed.xml"):
|
||||||
|
os.remove("build/books/feed.xml")
|
||||||
|
|
||||||
|
feedwrite = open("build/books/feed.xml", "a")
|
||||||
|
feedwrite.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n <channel>\n <atom:link href=\"https://tre.praze.net/trackers/books/feed.xml\" rel=\"self\" type=\"application/rss+xml\" />\n <title>Book log</title>\n <link>https://tre.praze.net</link>\n <description>Feed for book updates</description>\n <language>en-gb</language>")
|
||||||
|
|
||||||
|
theyear = int(thisyear)
|
||||||
|
while theyear >= 1993:
|
||||||
|
yearlist = []
|
||||||
|
enddate = datetime.strptime((str(theyear) + "-12-31"),"%Y-%m-%d")
|
||||||
|
startdate = datetime.strptime((str(theyear) + "-01-01"),"%Y-%m-%d")
|
||||||
|
eachdate = enddate
|
||||||
|
while eachdate >= startdate:
|
||||||
|
for book in books:
|
||||||
|
if eachdate in book["readdates"]:
|
||||||
|
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Read"})
|
||||||
|
try:
|
||||||
|
if book["progressdates"][0] == eachdate:
|
||||||
|
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Reading"})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if book["obtaineddate"] == eachdate:
|
||||||
|
yearlist.append({"date":eachdate,"author":book["author"],"title":book["title"].replace("&","&"),"action":"Added"})
|
||||||
|
eachdate -= timedelta(days=1)
|
||||||
|
checkdate = enddate
|
||||||
|
for event in yearlist:
|
||||||
|
feedwrite.write(" <item>\n <title>" + event["action"] + " " + event["title"] + "</title>\n <pubDate>" + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 GMT</pubDate>\n <link>https://tre.praze.net</link>\n <guid isPermaLink=\"false\">" + event["action"] + "-" + event["author"].replace(" ","-") + event["title"].replace(" ","-") + "-" + event["date"].strftime("%Y-%m-%d") + "</guid>\n <description>" + event["action"] + " " + event["title"] + " by " + event["author"] + "</description>\n </item>\n")
|
||||||
|
checkdate = event["date"]
|
||||||
|
theyear -= 1
|
||||||
|
|
||||||
|
feedwrite.write(" </channel>\n</rss>")
|
||||||
|
feedwrite.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
bookfeed()
|
||||||
|
|
||||||
|
def filmfeed():
|
||||||
|
if not os.path.isdir("build/films"):
|
||||||
|
os.mkdir("build/films")
|
||||||
|
if os.path.exists("build/films/feed.xml"):
|
||||||
|
os.remove("build/films/feed.xml")
|
||||||
|
|
||||||
|
feedwrite = open("build/films/feed.xml", "a")
|
||||||
|
feedwrite.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n <channel>\n <atom:link href=\"https://tre.praze.net/trackers/films/feed.xml\" rel=\"self\" type=\"application/rss+xml\" />\n <title>Film log</title>\n <link>https://tre.praze.net</link>\n <description>Feed of films I have watched</description>\n <language>en-gb</language>")
|
||||||
|
|
||||||
|
theyear = int(thisyear)
|
||||||
|
while theyear >= 1993:
|
||||||
|
yearlist = []
|
||||||
|
enddate = datetime.strptime((str(theyear) + "-12-31"),"%Y-%m-%d")
|
||||||
|
startdate = datetime.strptime((str(theyear) + "-01-01"),"%Y-%m-%d")
|
||||||
|
eachdate = enddate
|
||||||
|
while eachdate >= startdate:
|
||||||
|
for film in films:
|
||||||
|
if film["watched"] == eachdate:
|
||||||
|
yearlist.append({"date":eachdate,"id":film["id"].replace("&","&")})
|
||||||
|
eachdate -= timedelta(days=1)
|
||||||
|
checkdate = enddate
|
||||||
|
for event in yearlist:
|
||||||
|
feedwrite.write(" <item>\n <title>Watched " + event["id"] + "</title>\n <pubDate>" + event["date"].strftime("%a, %-d %b %Y") + " 00:00:00 GMT</pubDate>\n <link>https://tre.praze.net</link>\n <guid isPermaLink=\"false\">" + event["id"].replace(" ","-") + "-" + event["date"].strftime("%Y-%m-%d") + "</guid>\n <description>Watched " + event["id"] + "</description>\n </item>\n")
|
||||||
|
checkdate = event["date"]
|
||||||
|
theyear -= 1
|
||||||
|
|
||||||
|
feedwrite.write(" </channel>\n</rss>")
|
||||||
|
feedwrite.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
filmfeed()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue