-
Notifications
You must be signed in to change notification settings - Fork 0
/
omdb.py
27 lines (24 loc) · 879 Bytes
/
omdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from app.movie.models import Movie
from app import db
with open('../omdb.txt') as f:
lines = f.readlines()
COLUMNS = lines.pop(0).decode('iso-8859-1').replace('\r', '').replace('\n', '').split('\t')
count = 0
for line in lines:
cols = line.decode('iso-8859-1').split('\t')
data = {}
for i, col in enumerate(cols):
if col == 'N/A' or COLUMNS[i] == 'ID':
continue;
if COLUMNS[i] == 'imdbVotes':
data[COLUMNS[i]] = col.replace(',', '')
else:
data[COLUMNS[i]] = col
data['id'] = count
if 'Language' not in data or data['Language'] != 'English' or 'Poster' not in data:
continue;
print 'Adding movie', data['Title']
movie = Movie(**data)
db.session.add(movie)
count+=1
db.session.commit()