vcinema/update_wiki.py

89 lines
3.5 KiB
Python
Raw Normal View History

2022-04-15 17:29:19 +01:00
from wiki_pages import FilmsByCountry, FilmsByReference, FilmsByYear, HiddenThemes, KeywordScores, ViewingsCsv
2022-03-26 00:33:39 +00:00
from vcinema_utils import VCinemaUtils
import argparse
from progress.bar import IncrementalBar
def update_wiki(token_id, token_secret, update_csv, pages):
2022-03-26 00:33:39 +00:00
if update_csv:
print("Updating CSV")
2022-04-15 17:29:19 +01:00
ViewingsCsv.update_viewings_csv(token_id, token_secret)
2022-03-26 00:33:39 +00:00
print("Getting viewings")
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
update_films_by_year = 'years' in pages
update_films_by_country = 'countries' in pages
update_film_references = 'references' in pages
update_hidden_themes = 'themes' in pages
update_keyword_scores = 'scores' in pages
2022-03-26 00:33:39 +00:00
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:
2022-04-15 17:29:19 +01:00
films_by_year = FilmsByYear.get_films_by_year(viewings)
2022-03-26 00:33:39 +00:00
bar.next()
if update_films_by_country:
2022-04-15 17:29:19 +01:00
films_by_country = FilmsByCountry.get_films_by_country(viewings)
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:29:19 +01:00
films_by_reference = FilmsByReference.get_films_by_reference(viewings)
bar.next()
if update_hidden_themes:
2022-04-15 17:29:19 +01:00
hidden_themes = HiddenThemes.get_hidden_themes(viewings, token_id, token_secret)
bar.next()
if update_keyword_scores:
2022-04-16 09:30:47 +01:00
keyword_scores = KeywordScores.get_keyword_scores(viewings)
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-16 09:43:51 +01:00
FilmsByYear.update_page(films_by_year)
2022-03-26 00:33:39 +00:00
bar.next()
if update_films_by_country:
2022-04-16 09:43:51 +01:00
FilmsByCountry.update_page(films_by_country)
2022-03-26 00:33:39 +00:00
bar.next()
2022-04-08 23:00:53 +01:00
if update_film_references:
2022-04-16 09:43:51 +01:00
FilmsByReference.update_page(films_by_reference)
2022-04-08 23:00:53 +01:00
bar.next()
if update_hidden_themes:
2022-04-16 09:43:51 +01:00
HiddenThemes.update_page(hidden_themes)
bar.next()
if update_keyword_scores:
2022-04-16 09:43:51 +01:00
KeywordScores.update_page(keyword_scores)
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('--pages', nargs="+", default=['years', 'countries', 'references', 'themes', 'scores'], 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.pages)