In [1]:
import csv
from datetime import datetime
class Record:
def __init__(self, date, title, year, rating5, rating10, imdb_url):
self.date = datetime.strptime(date, '%Y-%m-%d')
self.title = title
self.year = int(year)
self.rating5 = int(rating5) if rating5.isdigit() else None
self.rating10 = int(rating10) if rating10.isdigit() else None
self.imdb_url = imdb_url
def __str__(self):
return '{} ({})'.format(self.title, self.year)
with open('ratings.csv', newline='') as f:
records = list(map(lambda r: Record(*r), list(csv.reader(f))[1:]))
Most recently watched movies:
In [2]:
for record in list(sorted(records, key=lambda r: r.date, reverse=True))[:10]:
print('{}, {}, {}/5'.format(record.date.strftime('%a %b %d %Y'), record, record.rating5))
Top rated movies:
In [3]:
for record in sorted(filter(lambda r: r.rating5 >= 5, records), key=lambda r: r.rating5, reverse=True):
print('{}/5, {}'.format(record.rating5, record))