Compare commits
No commits in common. "116e858cc267cb1efaf3e9407f0c8ff37ea92d70" and "06fa6729f7c0f7114598b54ca987096a5ad9d54a" have entirely different histories.
116e858cc2
...
06fa6729f7
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +0,0 @@
|
||||
|
||||
*.pyc
|
||||
.idea/*
|
||||
__pycache__/*
|
||||
.DS_Store
|
@ -4,7 +4,7 @@ import string
|
||||
from vcinema_utils import VCinemaUtils
|
||||
|
||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/references
|
||||
FILM_BY_REFERENCES_PAGE_ID = 62
|
||||
FILM_BY_REFERENCES_PAGE_ID = 63
|
||||
|
||||
|
||||
def get_films_by_reference(viewings):
|
||||
|
@ -1,16 +1,17 @@
|
||||
from bs4 import BeautifulSoup
|
||||
import hashlib
|
||||
|
||||
|
||||
from bookstack import Bookstack
|
||||
from vcinema_utils import VCinemaUtils
|
||||
|
||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/csv
|
||||
CSV_PAGE_ID = 11
|
||||
|
||||
|
||||
def update_viewings_csv(token_id, token_secret, check_existing=True):
|
||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/csv
|
||||
page_id = 11
|
||||
|
||||
print("Retrieving viewings page")
|
||||
html_page = Bookstack.get_page_html(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, CSV_PAGE_ID)
|
||||
html_page = Bookstack.get_page_html(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, page_id)
|
||||
|
||||
soup = BeautifulSoup(html_page, 'html.parser')
|
||||
csv_data = soup.find("code").text.strip().encode('utf-8')
|
||||
@ -25,7 +26,7 @@ def update_viewings_csv(token_id, token_secret, check_existing=True):
|
||||
if not check_existing or page_hash != existing_attachment_hash:
|
||||
print("Updating file")
|
||||
# bookstack update file via api doesn't work
|
||||
Bookstack.post_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, "vcinema.csv", csv_data, CSV_PAGE_ID)
|
||||
Bookstack.post_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, "vcinema.csv", csv_data, page_id)
|
||||
Bookstack.delete_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, existing_attachment_id)
|
||||
print("File updated")
|
||||
else:
|
||||
|
@ -1,74 +0,0 @@
|
||||
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, 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, 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)
|
@ -9,15 +9,15 @@ from bookstack import Bookstack
|
||||
|
||||
JACKNET_WIKI_URL = "https://wiki.jacknet.io"
|
||||
|
||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/csv
|
||||
CSV_PAGE_ID = 11
|
||||
|
||||
def get_viewings_csv_attachment_id(token_id, token_secret):
|
||||
attachments = Bookstack.get_attachments(JACKNET_WIKI_URL, token_id, token_secret)
|
||||
|
||||
# Page ID of "https://wiki.jacknet.io/books/vcinema/page/csv"
|
||||
page_id = 11
|
||||
viewings_csv_file_name = "vcinema.csv"
|
||||
|
||||
return next((x['id'] for x in attachments if x['uploaded_to'] == CSV_PAGE_ID and x['name'] == viewings_csv_file_name), None)
|
||||
return next((x['id'] for x in attachments if x['uploaded_to'] == page_id and x['name'] == viewings_csv_file_name), None)
|
||||
|
||||
|
||||
def get_vcinema_viewings(token_id, token_secret, viewings_csv=None, combine_repeat_viewings=True):
|
||||
@ -63,13 +63,13 @@ def increment_progressbar(bar, _):
|
||||
|
||||
def add_imdb_data_to_viewings(viewings, field_names, progressbar=None):
|
||||
with ThreadPoolExecutor(4) as executor:
|
||||
future_imdb_tasks = {executor.submit(IMDbUtils.get_movie, viewing['imdb_id']) for viewing in viewings}
|
||||
future_to_url = {executor.submit(IMDbUtils.get_movie, viewing['imdb_id']) for viewing in viewings}
|
||||
|
||||
if progressbar is not None:
|
||||
for this_future in future_imdb_tasks:
|
||||
for this_future in future_to_url:
|
||||
this_future.add_done_callback(functools.partial(increment_progressbar, progressbar))
|
||||
|
||||
for future in as_completed(future_imdb_tasks):
|
||||
for future in as_completed(future_to_url):
|
||||
imdb_data = future.result()
|
||||
|
||||
for viewing in viewings:
|
||||
@ -78,9 +78,6 @@ def add_imdb_data_to_viewings(viewings, field_names, progressbar=None):
|
||||
if field_name in imdb_data:
|
||||
viewing[field_name] = imdb_data[field_name]
|
||||
|
||||
if progressbar is not None:
|
||||
progressbar.finish()
|
||||
|
||||
|
||||
def filter_viewings(viewings, filter_field, progressbar=None):
|
||||
viewings_filtered = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user