|
| 1 | +import csv |
| 2 | +from collections import defaultdict, namedtuple, Counter |
| 3 | + |
| 4 | +MOVIE_DATA = 'movie_metadata.csv' |
| 5 | +NUM_TOP_DIRECTORS = 20 |
| 6 | +MIN_MOVIES = 4 |
| 7 | +MIN_YEAR = 1960 |
| 8 | + |
| 9 | +Movie = namedtuple('Movie', 'director title year score') |
| 10 | + |
| 11 | +def get_movies_by_director(data): |
| 12 | + '''Extracts all movies from csv and stores them in a dictionary |
| 13 | + where keys are directors, and values is a list of movies (named tuples)''' |
| 14 | + with open(data, newline='',encoding='utf8') as csvfile: |
| 15 | + reader = csv.DictReader(csvfile) |
| 16 | + headers = reader.fieldnames |
| 17 | + keep = ['director_name', 'movie_title', 'title_year', 'imdb_rating'] |
| 18 | + for row in reader if keep in headers: |
| 19 | + print(row) |
| 20 | + |
| 21 | + return |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +def get_average_scores(movies): |
| 26 | + '''Filter directors with < MIN_MOVIES and calculate averge score''' |
| 27 | + return directors |
| 28 | + |
| 29 | + |
| 30 | +def _calc_mean(movies): |
| 31 | + '''Helper method to calculate mean of list of Movie namedtuples''' |
| 32 | + pass |
| 33 | + |
| 34 | + |
| 35 | +def print_results(movies): |
| 36 | + '''Print directors ordered by highest average rating. For each director |
| 37 | + print his/her movies also ordered by highest rated movie. |
| 38 | + See http://pybit.es/codechallenge13.html for example output''' |
| 39 | + fmt_director_entry = '{counter}. {director:<52} {avg}' |
| 40 | + fmt_movie_entry = '{year}] {title:<50} {score}' |
| 41 | + sep_line = '-' * 60 |
| 42 | + pass |
| 43 | + |
| 44 | + |
| 45 | +def main(): |
| 46 | + |
| 47 | + get_movies_by_director(MOVIE_DATA) |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == '__main__': |
| 51 | + main() |
0 commit comments