Update update_films_by_year.py
This commit is contained in:
parent
6e941a13d1
commit
14c60c1bab
|
@ -1,20 +1,23 @@
|
||||||
import argparse
|
import argparse
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from progress.bar import Bar
|
from progress.bar import IncrementalBar
|
||||||
|
|
||||||
from bookstack import Bookstack
|
from bookstack import Bookstack
|
||||||
from vcinema_utils import VCinemaUtils
|
from vcinema_utils import VCinemaUtils
|
||||||
|
|
||||||
|
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
|
||||||
|
FILMS_BY_YEAR_PAGE_ID = 24
|
||||||
|
|
||||||
def build_table(films_by_year, progressbar=None):
|
|
||||||
|
def build_page(films_by_year, progressbar=None):
|
||||||
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
|
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
|
||||||
|
|
||||||
page_table = "| Year | Films |\n| - | - |\n"
|
page_table = "| Year | Films |\n| - | - |"
|
||||||
|
|
||||||
for year in films_by_year_sorted.keys():
|
for year in films_by_year_sorted.keys():
|
||||||
|
page_table += "\n"
|
||||||
page_table += str(year) + " | "
|
page_table += str(year) + " | "
|
||||||
page_table += "<br>".join("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_year_sorted[year])
|
page_table += "<br>".join("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_year_sorted[year])
|
||||||
page_table += "\n"
|
|
||||||
|
|
||||||
if progressbar is not None:
|
if progressbar is not None:
|
||||||
progressbar.next()
|
progressbar.next()
|
||||||
|
@ -30,21 +33,18 @@ def update_films_by_year(token_id, token_secret):
|
||||||
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
||||||
|
|
||||||
viewing_count = len(viewings)
|
viewing_count = len(viewings)
|
||||||
with Bar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
with IncrementalBar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
||||||
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['year'], bar)
|
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['year'], bar)
|
||||||
|
|
||||||
with Bar('Processing viewing data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
with IncrementalBar('Processing viewing data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
||||||
viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year', bar)
|
viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year', bar)
|
||||||
|
|
||||||
year_count = len(viewings_by_year)
|
year_count = len(viewings_by_year)
|
||||||
with Bar('Generating table', max=year_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
with IncrementalBar('Generating table', max=year_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
||||||
film_by_year_table = build_table(viewings_by_year, bar)
|
films_by_year_page = build_page(viewings_by_year, bar)
|
||||||
|
|
||||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
|
|
||||||
page_id = 24
|
|
||||||
|
|
||||||
print("Updating page")
|
print("Updating page")
|
||||||
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, page_id, markdown=film_by_year_table)
|
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, FILMS_BY_YEAR_PAGE_ID, markdown=films_by_year_page)
|
||||||
|
|
||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue