-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movie rating API from json OMDb and TasteDive (w_o keys).py
62 lines (46 loc) · 1.64 KB
/
Movie rating API from json OMDb and TasteDive (w_o keys).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
62
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 5 09:32:02 2020
@author: Pranav Tumkur
"""
import requests
import json
def get_movies_from_tastedive(movie):
baseurl="https://tastedive.com/api/similar"
params_diction = {}
params_diction['q']=movie
params_diction['k']='362734-********-******' #Enter your API key here
params_diction['type']='movies'
params_diction['limit']=5
response = requests.get(baseurl, params=params_diction)
#print(response.url)
x = response.json()
extract_movie_titles = list()
for y in x['Similar']['Results']:
extract_movie_titles.append(y['Name'])
return(extract_movie_titles)
def get_movie_data(movie):
baseurl='http:https://www.omdbapi.com/?apikey=*******' #Enter your API key here
params_diction = {}
params_diction['t']=movie
params_diction['r']='json'
response = requests.get(baseurl, params=params_diction)
#print(response.url)
return response.json()
def get_movie_rating(movie):
results_omdb = get_movie_data(movie)
for z in results_omdb['Ratings']:
if z['Source']=='Rotten Tomatoes':
return(z['Value'])
def get_sorted_recommendations(movie):
extract_movie_titles=get_movies_from_tastedive(movie)
#print(extract_movie_titles)
TnR=dict()
for x in extract_movie_titles:
TnR[x]=get_movie_rating(x)
TnR_sorted=sorted(TnR.keys(), key= lambda x:TnR[x][:2])
print(TnR_sorted)
while True:
inp=input('Enter movie name : ')
if inp=='': break
else: get_sorted_recommendations(inp)