diff --git a/update_viewings_csv.py b/update_viewings_csv.py index 6091b72..017f75c 100644 --- a/update_viewings_csv.py +++ b/update_viewings_csv.py @@ -7,7 +7,7 @@ from bookstack import Bookstack from vcinema_utils import VCinemaUtils -def update_viewings_csv_file_from_page(token_id, token_secret): +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 @@ -17,23 +17,21 @@ def update_viewings_csv_file_from_page(token_id, token_secret): soup = BeautifulSoup(html_page, 'html.parser') csv_data = soup.find("code").text.strip().encode('utf-8') - print("Retrieving existing file") - existing_attachment_id = VCinemaUtils.get_viewings_csv_attachment_id(token_id, token_secret) + if check_existing: + print("Retrieving existing file") + existing_attachment_id = VCinemaUtils.get_viewings_csv_attachment_id(token_id, token_secret) + attachment = Bookstack.get_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, existing_attachment_id) + existing_attachment_hash = hashlib.md5(attachment).hexdigest() + page_hash = hashlib.md5(csv_data).hexdigest() - attachment = Bookstack.get_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, existing_attachment_id) - - existing_attachment_hash = hashlib.md5(attachment).hexdigest() - - page_hash = hashlib.md5(csv_data).hexdigest() - - if page_hash != existing_attachment_hash: + 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, page_id) Bookstack.delete_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, existing_attachment_id) - print("Done") + print("File updated") else: - print("File already up to date") + print("File already up-to-date") if __name__ == '__main__': @@ -43,4 +41,4 @@ if __name__ == '__main__': args = parser.parse_args() - update_viewings_csv_file_from_page(args.token_id, args.token_secret) + update_viewings_csv(args.token_id, args.token_secret)