Created
April 22, 2021 12:35
-
-
Save pl-phan/e7afbd66b6e14cce4a72c3b4279230e1 to your computer and use it in GitHub Desktop.
Random films from IMDb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import webbrowser | |
import numpy as np | |
import pandas as pd | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--csv-file', default='./WATCHLIST.csv') | |
parser.add_argument('--n', default=5) | |
parser.add_argument('--min-rating', default=None) | |
parser.add_argument('--max-runtime', default=None) | |
parser.add_argument('--min-year', default=None) | |
parser.add_argument('--max-year', default=None) | |
args = parser.parse_args() | |
watchlist = pd.read_csv(args.csv_file) | |
columns = {'Title': 'title', 'IMDb Rating': 'rating', 'Runtime (mins)': 'runtime', | |
'URL': 'url', 'Title Type': 'type', 'Year': 'year'} | |
watchlist = watchlist.reindex(columns.keys(), axis='columns').rename(columns=columns) | |
watchlist = watchlist.loc[~watchlist.rating.isna()] | |
if args.min_rating is not None: | |
watchlist = watchlist.loc[watchlist.rating >= args.min_rating] | |
if args.max_runtime is not None: | |
watchlist = watchlist.loc[watchlist.runtime <= args.max_runtime] | |
if args.min_year is not None: | |
watchlist = watchlist.loc[watchlist.year >= args.min_year] | |
if args.max_year is not None: | |
watchlist = watchlist.loc[watchlist.year <= args.max_year] | |
rng = np.random.default_rng() | |
choice = watchlist.iloc[rng.choice(len(watchlist), size=args.n, replace=False)] | |
print('Picked from {} movies :'.format(len(watchlist))) | |
for _, row in choice.iterrows(): | |
print('\t' + row.title) | |
webbrowser.open(row.url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment