Created
January 18, 2014 23:14
-
-
Save liddiard/4469a0f8ed5542065cad to your computer and use it in GitHub Desktop.
showstarter imdb import
This file contains hidden or 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 sys | |
ENTRY_START = 297 | |
RATING_RANGE = (20, 24) | |
TITLE_START = 26 | |
input_file = sys.argv[1] | |
with open(input_file, 'r') as f: | |
entries = [line.strip() for line in f] | |
start = RATING_RANGE[0] | |
end = RATING_RANGE[1] | |
capturing = False | |
prev_rating = None | |
prev_title = None | |
episode = r'{.*}' | |
for entry in entries[ENTRY_START:ENTRY_START+10]: | |
try: | |
rating = float(entry[start:end]) | |
title = entry[TITLE_START:] | |
except ValueError: | |
break | |
if capturing and re.match(episode, entry): | |
print "NEW EPISODE:", | |
else: | |
if re.match(episode, entry): | |
print "NEW TV SHOW:", prev_rating, prev_title | |
capturing = True | |
prev_rating = rating | |
prev_title = title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment