vcinema/wiki_pages/FilmsByYear.py

36 lines
988 B
Python
Raw Permalink Normal View History

2022-02-20 21:26:38 +00:00
from collections import OrderedDict
2022-04-16 09:43:51 +01:00
from bookstack import Bookstack
2022-02-20 21:26:38 +00:00
from vcinema_utils import VCinemaUtils
2022-03-25 17:55:52 +00:00
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
2022-04-15 17:29:19 +01:00
PAGE_ID = 24
2022-02-20 21:26:38 +00:00
2022-03-25 17:55:52 +00:00
2022-03-25 22:17:11 +00:00
def get_films_by_year(viewings):
2022-12-19 22:26:38 +00:00
viewings_filtered_by_year = VCinemaUtils.filter_films(viewings, "year")
2022-03-25 22:17:11 +00:00
return viewings_filtered_by_year
2022-04-16 09:43:51 +01:00
def update_page(token_id, token_secret, films_by_year):
page = build_page(films_by_year)
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID, markdown=page)
2022-04-03 22:27:49 +01:00
def build_page(films_by_year):
2022-02-27 13:54:18 +00:00
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
2022-02-20 21:26:38 +00:00
2022-04-03 22:27:49 +01:00
page = "| Year | Films |\n| - | - |"
2022-02-27 14:34:23 +00:00
for year in films_by_year_sorted.keys():
2022-04-03 22:27:49 +01:00
page += "\n"
2022-04-08 22:01:58 +01:00
row_data = []
row_data.append(str(year))
row_data.append(VCinemaUtils.get_film_list(films_by_year_sorted[year]))
page += " | ".join(row_data)
2022-02-20 21:26:38 +00:00
2022-04-03 22:27:49 +01:00
return page