-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-collection.py
61 lines (52 loc) · 1.89 KB
/
data-collection.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
def get_movies_from_tastedive(movieName, key="327878-course3p-I4ZNBN4A"):
baseurl="https://tastedive.com/api/similar"
params_d = {}
params_d["q"]= movieName
params_d["k"]= key
params_d["type"]= "movies"
params_d["limit"] = "5"
resp = requests.get(baseurl, params=params_d)
print(resp.url)
respDic = resp.json()
return respDic
def extract_movie_titles(movieName):
result=[]
for listRes in movieName['Similar']['Results']:
result.append(listRes['Name'])
return result
def get_related_titles(listMovieName):
if listMovieName != []:
auxList=[]
relatedList=[]
for movieName in listMovieName:
auxList = extract_movie_titles(get_movies_from_tastedive(movieName))
for movieNameAux in auxList:
if movieNameAux not in relatedList:
relatedList.append(movieNameAux)
return relatedList
return listMovieName
def get_movie_data(movieName, key="546c6742"):
baseurl= "http://www.omdbapi.com/"
params_d = {}
params_d["t"]= movieName
params_d["apikey"]= key
params_d["r"]= "json"
resp = requests.get(baseurl, params=params_d)
print(resp.url)
respDic = resp.json()
return respDic
def get_movie_rating(movieNameJson):
strRanting=""
for typeRantingList in movieNameJson["Ratings"]:
if typeRantingList["Source"]== "Rotten Tomatoes":
strRanting = typeRantingList["Value"]
if strRanting != "":
ranting = int(strRanting[:2])
else: ranting = 0
return ranting
def get_sorted_recommendations(listMovieTitle):
listMovie= get_related_titles(listMovieTitle)
listMovie= sorted(listMovie, key = lambda movieName: (get_movie_rating(get_movie_data(movieName)), movieName), reverse=True)
return listMovie
print(get_sorted_recommendations(["Bridesmaids", "Sherlock Holmes"]))