fix csv reading
This commit is contained in:
parent
b9a4ee9530
commit
d3e575dd93
|
@ -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]
|
||||||
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:
|
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])
|
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]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue