75 lines
2.8 KiB
Python
75 lines
2.8 KiB
Python
from bookstack import Bookstack
|
|
from update_films_by_country import get_films_by_country, build_page as build_films_by_country_page, FILMS_BY_COUNTRY_PAGE_ID
|
|
from update_films_by_year import get_films_by_year, build_page as build_films_by_year_page, FILMS_BY_YEAR_PAGE_ID
|
|
from vcinema_utils import VCinemaUtils
|
|
from update_viewings_csv import update_viewings_csv
|
|
|
|
import argparse
|
|
from progress.bar import IncrementalBar
|
|
|
|
|
|
def update_wiki(token_id, token_secret, update_csv=False, update_films_by_year=True, update_films_by_country=True):
|
|
if update_csv:
|
|
print("Updating CSV")
|
|
update_viewings_csv(token_id, token_secret)
|
|
|
|
print("Getting viewings")
|
|
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
|
|
|
data_fields = []
|
|
if update_films_by_year:
|
|
data_fields.append("year")
|
|
|
|
if update_films_by_country:
|
|
data_fields.append("countries")
|
|
|
|
viewing_count = len(viewings)
|
|
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, data_fields, bar)
|
|
|
|
update_page_count = 0
|
|
if update_films_by_year:
|
|
update_page_count += 1
|
|
if update_films_by_country:
|
|
update_page_count += 1
|
|
|
|
with IncrementalBar('Processing viewing data', max=update_page_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
if update_films_by_year:
|
|
films_by_year = get_films_by_year(viewings)
|
|
bar.next()
|
|
if update_films_by_country:
|
|
films_by_country = get_films_by_country(viewings)
|
|
bar.next()
|
|
|
|
bar.finish()
|
|
|
|
with IncrementalBar('Generating pages', max=update_page_count, check_tty=False) as bar:
|
|
if update_films_by_year:
|
|
films_by_year_page = build_films_by_year_page(films_by_year)
|
|
bar.next()
|
|
if update_films_by_country:
|
|
films_by_country_page = build_films_by_country_page(films_by_country)
|
|
bar.next()
|
|
|
|
bar.finish()
|
|
|
|
with IncrementalBar('Updating pages', max=update_page_count, check_tty=False) as bar:
|
|
if update_films_by_year:
|
|
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, FILMS_BY_YEAR_PAGE_ID, markdown=films_by_year_page)
|
|
bar.next()
|
|
if update_films_by_country:
|
|
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, FILMS_BY_COUNTRY_PAGE_ID, html=films_by_country_page)
|
|
bar.next()
|
|
|
|
bar.finish()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description='Update wiki pages.')
|
|
parser.add_argument('token_id', help='API token ID.')
|
|
parser.add_argument('token_secret', help='API token secret.')
|
|
|
|
args = parser.parse_args()
|
|
|
|
update_wiki(args.token_id, args.token_secret)
|