fix csv reading

This commit is contained in:
Sarah 2022-03-12 16:08:02 +00:00
parent b9a4ee9530
commit d3e575dd93
1 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,6 @@
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
@ -28,15 +29,17 @@ def get_vcinema_viewings(token_id, token_secret, viewings_csv=None, combine_repe
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(",")
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: 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('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]