use csv file instead of reading from csv page
This commit is contained in:
parent
5456a138c0
commit
3772e7f190
@ -1,4 +1,3 @@
|
|||||||
from bs4 import BeautifulSoup
|
|
||||||
from progress.bar import Bar
|
from progress.bar import Bar
|
||||||
|
|
||||||
from imdb_utils import IMDbUtils
|
from imdb_utils import IMDbUtils
|
||||||
@ -8,16 +7,25 @@ from wiki_utils import WikiUtils
|
|||||||
JACKNET_WIKI_URL = "https://wiki.jacknet.io"
|
JACKNET_WIKI_URL = "https://wiki.jacknet.io"
|
||||||
|
|
||||||
|
|
||||||
def get_vcinema_viewings(token_id, token_secret):
|
def get_viewings_csv_attachment_id(token_id, token_secret):
|
||||||
# Page ID of /Vcinema/CSV
|
attachments = WikiUtils.get_attachments(JACKNET_WIKI_URL, token_id, token_secret)
|
||||||
|
|
||||||
|
# Page ID of "https://wiki.jacknet.io/books/vcinema/page/csv")
|
||||||
page_id = 11
|
page_id = 11
|
||||||
|
viewings_csv_file_name = "vcinema.csv"
|
||||||
|
|
||||||
html_page = WikiUtils.get_page_export_html(page_id, JACKNET_WIKI_URL, token_id, token_secret)
|
return next((x['id'] for x in attachments if x['uploaded_to'] == page_id and x['name'] == viewings_csv_file_name), None)
|
||||||
|
|
||||||
soup = BeautifulSoup(html_page, 'html.parser')
|
|
||||||
elements = soup.find("code").text.strip().split("\n")
|
def get_vcinema_viewings(token_id, token_secret):
|
||||||
headers = elements.pop(0).split(",")
|
attachment_id = get_viewings_csv_attachment_id(token_id, token_secret)
|
||||||
viewings = [dict(zip(headers, row.split(","))) for row in elements]
|
|
||||||
|
viewings_csv = WikiUtils.get_attachment_contents(attachment_id, JACKNET_WIKI_URL, token_id, token_secret)
|
||||||
|
viewings_csv = viewings_csv.decode("utf-8")
|
||||||
|
viewings_csv_rows = viewings_csv.strip().split("\n")
|
||||||
|
|
||||||
|
headers = viewings_csv_rows.pop(0).split(",")
|
||||||
|
viewings = [dict(zip(headers, row.split(","))) for row in viewings_csv_rows]
|
||||||
|
|
||||||
return viewings
|
return viewings
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user