vcinema/update_wiki.py

115 lines
5.6 KiB
Python
Raw Normal View History

2022-03-26 00:33:39 +00:00
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
2022-04-15 17:22:04 +01:00
from wiki_pages import References
2022-03-26 00:33:39 +00:00
from update_films_by_year import get_films_by_year, build_page as build_films_by_year_page, FILMS_BY_YEAR_PAGE_ID
from update_hidden_themes import get_hidden_themes, build_page as build_hidden_themes_page, HIDDEN_THEMES_PAGE_ID
from update_keywords_scores import get_keyword_scores, build_page as build_keyword_scores_page, KEYWORD_SCORES_PAGE_ID
2022-03-26 00:33:39 +00:00
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, update_films_by_year, update_films_by_country,
update_film_references, update_hidden_themes, update_keyword_scores):
2022-03-26 00:33:39 +00:00
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")
if update_film_references or update_hidden_themes or update_keyword_scores:
2022-04-08 23:00:53 +01:00
data_fields.append("keywords")
2022-03-26 00:33:39 +00:00
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 = sum([update_films_by_year, update_films_by_country, update_film_references,
update_hidden_themes, update_keyword_scores])
2022-03-26 00:33:39 +00:00
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()
2022-04-08 23:00:53 +01:00
if update_film_references:
2022-04-15 17:22:04 +01:00
films_by_reference = References.get_films_by_reference(viewings)
bar.next()
if update_hidden_themes:
hidden_themes = get_hidden_themes(viewings, token_id, token_secret)
bar.next()
if update_keyword_scores:
keyword_scores = get_keyword_scores(viewings)
bar.next()
2022-03-26 00:33:39 +00:00
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()
2022-04-08 23:00:53 +01:00
if update_film_references:
2022-04-15 17:22:04 +01:00
films_by_reference_page = References.build_page(films_by_reference)
bar.next()
if update_hidden_themes:
hidden_themes_page = build_hidden_themes_page(hidden_themes)
bar.next()
if update_keyword_scores:
keyword_scores_page = build_keyword_scores_page(keyword_scores)
bar.next()
2022-03-26 00:33:39 +00:00
bar.finish()
with IncrementalBar('Updating pages', max=update_page_count, check_tty=False) as bar:
if update_films_by_year:
2022-04-03 15:50:20 +01:00
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, FILMS_BY_YEAR_PAGE_ID, markdown=films_by_year_page)
2022-03-26 00:33:39 +00:00
bar.next()
if update_films_by_country:
2022-04-03 16:22:27 +01:00
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, FILMS_BY_COUNTRY_PAGE_ID, markdown=films_by_country_page)
2022-03-26 00:33:39 +00:00
bar.next()
2022-04-08 23:00:53 +01:00
if update_film_references:
2022-04-15 17:22:04 +01:00
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, References.PAGE_ID, markdown=films_by_reference_page)
2022-04-08 23:00:53 +01:00
bar.next()
if update_hidden_themes:
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, HIDDEN_THEMES_PAGE_ID, markdown=hidden_themes_page)
bar.next()
if update_keyword_scores:
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, KEYWORD_SCORES_PAGE_ID, markdown=keyword_scores_page)
bar.next()
2022-03-26 00:33:39 +00:00
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.')
2022-04-15 17:12:22 +01:00
parser.add_argument('--update_csv', help='Update viewings.csv file, default: True', default=True, required=False)
parser.add_argument('--update_films_by_year', help='Update films by release year page, default: True', default=True, required=False)
2022-04-08 23:57:39 +01:00
parser.add_argument('--update_films_by_country', help='Update films by country page, default: True', default=True, required=False)
2022-04-15 17:12:22 +01:00
parser.add_argument('--update_films_by_reference', help='Update films by reference page, default: True', default=True, required=False)
parser.add_argument('--update_hidden_themes', help='Update hidden themes page, default: True', default=True, required=False)
parser.add_argument('--update_keyword_scores', help='Update keyword scores page - THIS TAKES A WHILE, default: False', default=False, required=False)
2022-04-08 21:41:46 +01:00
2022-03-26 00:33:39 +00:00
args = parser.parse_args()
update_wiki(args.token_id, args.token_secret, args.update_csv, args.update_films_by_year,
args.update_films_by_country, args.update_films_by_reference, args.update_hidden_themes,
args.update_keyword_scores)