2022-02-20 21:26:38 +00:00
|
|
|
import argparse
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
|
|
|
|
from vcinema_utils import VCinemaUtils
|
|
|
|
from wiki_utils import WikiUtils
|
|
|
|
|
|
|
|
|
|
|
|
JACKNET_WIKI_URL = "https://wiki.jacknet.io"
|
|
|
|
|
|
|
|
|
2022-02-20 21:30:15 +00:00
|
|
|
def build_table(films_by_year):
|
|
|
|
films_by_year_descending = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
|
2022-02-20 21:26:38 +00:00
|
|
|
|
|
|
|
page_table = "| Year | Films |\n| - | - |\n"
|
2022-02-20 21:30:15 +00:00
|
|
|
for year in films_by_year_descending.keys():
|
2022-02-20 21:26:38 +00:00
|
|
|
page_table += str(year) + " | "
|
2022-02-20 21:30:15 +00:00
|
|
|
page_table += "<br>".join("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_year_descending[year])
|
2022-02-20 21:26:38 +00:00
|
|
|
page_table += "\n"
|
|
|
|
|
|
|
|
return page_table
|
|
|
|
|
|
|
|
|
|
|
|
def update_films_by_year_page(token_id, token_secret):
|
|
|
|
print("Retrieving VCinema viewings")
|
|
|
|
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
|
|
|
|
|
|
|
print("Retrieving movie data")
|
|
|
|
VCinemaUtils.add_imdb_data_to_viewings(viewings, 'year')
|
|
|
|
|
|
|
|
print("Processing viewing data")
|
|
|
|
viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year')
|
|
|
|
|
|
|
|
print("Generating table")
|
|
|
|
film_by_year_table = build_table(viewings_by_year)
|
|
|
|
|
|
|
|
wiki_url = JACKNET_WIKI_URL
|
|
|
|
|
|
|
|
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
|
|
|
|
page_id = "24"
|
|
|
|
|
|
|
|
print("Updating page")
|
|
|
|
WikiUtils.update_page(page_id, film_by_year_table, wiki_url, token_id, token_secret)
|
|
|
|
|
|
|
|
print("Done!")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description='Update page displaying VCinema films sorted by release year.')
|
|
|
|
parser.add_argument('token_id', help='API token ID.')
|
|
|
|
parser.add_argument('token_secret', help='API token secret.')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
update_films_by_year_page(args.token_id, args.token_secret)
|