Skip to content

Instantly share code, notes, and snippets.

@liddiard
Created January 18, 2014 23:14
Show Gist options
  • Save liddiard/4469a0f8ed5542065cad to your computer and use it in GitHub Desktop.
Save liddiard/4469a0f8ed5542065cad to your computer and use it in GitHub Desktop.
showstarter imdb import
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