feature/use-update-attachment-method #6
|
@ -1 +1 @@
|
||||||
Subproject commit 5d2e08eabc8186848630f1aa790c72260b9751b0
|
Subproject commit 8f6e38cb337bcf51b0790f2db7001681ceb9338f
|
|
@ -1,5 +1,4 @@
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import hashlib
|
|
||||||
|
|
||||||
from bookstack import Bookstack
|
from bookstack import Bookstack
|
||||||
from vcinema_utils import VCinemaUtils
|
from vcinema_utils import VCinemaUtils
|
||||||
|
@ -8,25 +7,14 @@ from vcinema_utils import VCinemaUtils
|
||||||
PAGE_ID = 11
|
PAGE_ID = 11
|
||||||
|
|
||||||
|
|
||||||
def update_viewings_csv(token_id, token_secret, check_existing=True):
|
def update_viewings_csv(token_id, token_secret):
|
||||||
print("Retrieving viewings page")
|
print("Retrieving viewings page")
|
||||||
html_page = Bookstack.get_page_html(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID)
|
html_page = Bookstack.get_page_html(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID)
|
||||||
|
|
||||||
soup = BeautifulSoup(html_page, 'html.parser')
|
soup = BeautifulSoup(html_page, 'html.parser')
|
||||||
csv_data = soup.find("code").text.strip().encode('utf-8')
|
csv_data = soup.find("code").text.strip().encode('utf-8')
|
||||||
|
|
||||||
if check_existing:
|
|
||||||
print("Retrieving existing file")
|
|
||||||
existing_attachment_id = VCinemaUtils.get_viewings_csv_attachment_id(token_id, token_secret)
|
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()
|
|
||||||
|
|
||||||
if not check_existing or page_hash != existing_attachment_hash:
|
|
||||||
print("Updating file")
|
print("Updating file")
|
||||||
# bookstack update file via api doesn't work
|
Bookstack.update_attachment(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, existing_attachment_id, "vcinema.csv", csv_data, 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")
|
print("File updated")
|
||||||
else:
|
|
||||||
print("File already up-to-date")
|
|
||||||
|
|
Loading…
Reference in New Issue