#!/usr/bin/env python from imdb import IMDb import os, re, threading, time, sys, subprocess from time import gmtime, strftime path = os.path.dirname(sys.argv[0]) ia = IMDb() movie_list = [] status_list = [] threads = [] query = [] html = """ My Movie List
""" # Open the movie list & split the columns file_ = open(path + '/movie_list', 'r') tmp_names = tmp_status = file_.read() file_.close() tmp_names = re.sub(r'\).*', ')', tmp_names) tmp_status = re.sub(r'\]|.*\[', '', tmp_status) movie_list = tmp_names.splitlines() status_list = tmp_status.splitlines() # Scan IMDb for a given movie and append it to the html # This collects rating, genres, official name and a hyperlink def worker(arg, index): save_stdout = sys.stdout sys.stdout = open('trash', 'w') query = ia.search_movie(arg) sys.stdout = save_stdout movie = query[0] ia.update(movie) movie['ID'] = query[0].movieID if 'genres' not in movie.keys(): movie['genres'] = 'N/A' if 'rating' not in movie.keys(): movie['rating'] = 'N/A' global html html = (html + '\n\t') # Progress bar. Enough said import progressbar bar = progressbar.ProgressBar(max_value=len(movie_list)) for idx, val in enumerate(movie_list): t = threading.Thread(target=worker, args=(val, idx,)) threads.append(t) t.start() bar.update(idx+1) time.sleep(0.2) if len(threads)%16 == 0: time.sleep(6) for x in threads: x.join() # Just a fancy scrollbar for the html scroll = """ """ html += ('\n\t\n
Index Title Year IMDb Rating Genre Status
' + str(index+1) + '' + '' + str(movie['title']) + '' + str(movie['year']) + '' + str(movie['rating']) + '' + re.sub(r'\[|\]|\'', '', str(movie['genres'])) + '' + str(status_list[index]) + '
\n' + '\nGenerated on: ' + strftime('%Y-%m-%d %H:%M:%S', gmtime()) + ' by ' + sys.argv[0] + scroll + '\n') file_ = open(path + '/index.html', 'wb') file_.write(html.encode('utf8')) file_.close()