-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbuild_dataset.py
More file actions
31 lines (27 loc) · 821 Bytes
/
build_dataset.py
File metadata and controls
31 lines (27 loc) · 821 Bytes
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 os
import json
import requests
API_KEY = os.environ.get("OMDB_API")
OMDB_URL = "http://www.omdbapi.com/?i=tt%s&plot=full&r=json&apikey=%s"
def main():
fdata = open("./data/extra_data.json", 'w')
flink = open("./ml-latest-small/links.csv", 'r')
for line in flink:
if line.startswith("movieId"):
continue
mid, imdb_id, _ = line.strip().split(",")
resp = requests.get(OMDB_URL % (imdb_id, API_KEY))
print(imdb_id)
print(resp.text)
resp_json = json.loads(resp.text)
if "Error" in resp_json:
print("Encountered an error.")
break
json.dump(resp_json, fdata)
fdata.write("\n")
flink.close()
fdata.close()
if __name__ == "__main__":
main()