Compare commits
3 Commits
b32d5aa6c6
...
d3e575dd93
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d3e575dd93 | ||
![]() |
b9a4ee9530 | ||
![]() |
cd4b392573 |
@ -1,5 +1,6 @@
|
||||
from collections import Counter
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
import csv
|
||||
import functools
|
||||
|
||||
from imdb_utils import IMDbUtils
|
||||
@ -19,23 +20,26 @@ def get_viewings_csv_attachment_id(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)
|
||||
|
||||
|
||||
def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True):
|
||||
def get_vcinema_viewings(token_id, token_secret, viewings_csv=None, combine_repeat_viewings=True):
|
||||
if viewings_csv is None:
|
||||
attachment_id = get_viewings_csv_attachment_id(token_id, token_secret)
|
||||
|
||||
viewings_csv = Bookstack.get_attachment(JACKNET_WIKI_URL, token_id, token_secret, attachment_id)
|
||||
|
||||
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]
|
||||
csvreader = csv.reader(viewings_csv_rows, delimiter=',', quotechar='"')
|
||||
viewings = [dict(zip(headers, list(row))) for row in csvreader]
|
||||
|
||||
if combine_repeat_viewings:
|
||||
for viewing in viewings:
|
||||
viewing['viewings'] = [{'date_watched': viewing['date_watched'], 'season': viewing['season'], 'rating': viewing['rating']}]
|
||||
viewing['viewings'] = [
|
||||
{'date_watched': viewing['date_watched'], 'season': viewing['season'], 'rating': viewing['rating']}]
|
||||
viewing.pop('date_watched')
|
||||
viewing.pop('season')
|
||||
viewing.pop('rating')
|
||||
|
||||
if combine_repeat_viewings:
|
||||
watch_counts = Counter([x['imdb_id'] for x in viewings])
|
||||
repeat_watches = [k for k, v in watch_counts.items() if v > 1]
|
||||
|
||||
@ -45,7 +49,7 @@ def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True):
|
||||
first_watch = viewings[viewing_indexes[0]]
|
||||
|
||||
for index in viewing_indexes[1::]:
|
||||
first_watch['viewings'].append(viewings[index]['viewings'])
|
||||
first_watch['viewings'].extend(viewings[index]['viewings'])
|
||||
|
||||
for index in reversed(viewing_indexes[1::]):
|
||||
viewings.pop(index)
|
||||
|
Loading…
x
Reference in New Issue
Block a user