-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathletterboxd_to_movielens.py
31 lines (25 loc) · 1.05 KB
/
letterboxd_to_movielens.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
28
29
30
31
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
import imdb
import sys
reload(sys)
sys.setdefaultencoding("utf8")
if len(sys.argv) < 2:
print "Usage: python letterboxd_to_movielens.py <filename>"
sys.exit()
ia = imdb.IMDb()
out = "\"position\",\"Const\",\"created\",\"modified\",\"description\",\"Title\",\"Title type\",\"Directors\",\"Your Rating\",\"IMDb Rating\",\"Runtime (mins)\",\"Year\",\"Genres\",\"Num. Votes\",\"Release Date (month/day/year)\",\"URL\"\n"
with open(sys.argv[1]) as fin:
content = csv.reader(fin, delimiter=',')
n_movies = len(list(content)[1:])
fin.seek(0)
content.next()
for idx,row in enumerate(content):
movie = ia.search_movie(row[1])[0]
url = ia.get_imdbURL(movie)
print str(idx+1) + "/" + str(n_movies)
out += "\"" + str(idx+1) + "\",\"" + url.split('/')[4] + "\",\" \",\" \",\" \",\"" + row[1] + "\",\" \",\" \",\"" + str(int(float(row[4].strip())*2)) + "\",\" \",\" \",\"" + row[2] + "\",\" \",\" \",\" \",\"" + url + "\"\n"
with open("ratings.csv", "w") as fout:
fout.write(out)
print "Done!"