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