From 93033b3f1c00c0ca3eb71ac5d69e44d7eebfa230 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 8 Mar 2022 22:44:20 +0000 Subject: [PATCH] add season and rating to viewing list for each film --- vcinema_utils/VCinemaUtils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vcinema_utils/VCinemaUtils.py b/vcinema_utils/VCinemaUtils.py index 9fde0a8..6a1240a 100644 --- a/vcinema_utils/VCinemaUtils.py +++ b/vcinema_utils/VCinemaUtils.py @@ -29,6 +29,12 @@ def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True): 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') + 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] @@ -37,10 +43,9 @@ def get_vcinema_viewings(token_id, token_secret, combine_repeat_viewings=True): viewing_indexes = [index for index, viewing in enumerate(viewings) if viewing['imdb_id'] == film] first_watch = viewings[viewing_indexes[0]] - first_watch['date_watched'] = [first_watch['date_watched']] for index in viewing_indexes[1::]: - first_watch['date_watched'].append(viewings[index]['date_watched']) + first_watch['viewings'].append(viewings[index]['viewings']) for index in reversed(viewing_indexes[1::]): viewings.pop(index)