diff --git a/vcinema_utils/VCinemaUtils.py b/vcinema_utils/VCinemaUtils.py index c617e85..88e860f 100644 --- a/vcinema_utils/VCinemaUtils.py +++ b/vcinema_utils/VCinemaUtils.py @@ -1,5 +1,6 @@ from collections import Counter from concurrent.futures import ThreadPoolExecutor, as_completed +import csv import functools 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") headers = viewings_csv_rows.pop(0).split(",") - viewings = [dict(zip(headers, row.split(","))) for row in viewings_csv_rows] - - for viewing in viewings: - viewing['viewings'] = [{'date_watched': viewing['date_watched'], 'season': viewing['season'], 'rating': viewing['rating']}] - viewing.pop('date_watched') - viewing.pop('season') - viewing.pop('rating') + 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.pop('date_watched') + viewing.pop('season') + viewing.pop('rating') + watch_counts = Counter([x['imdb_id'] for x in viewings]) repeat_watches = [k for k, v in watch_counts.items() if v > 1]