-
Notifications
You must be signed in to change notification settings - Fork 1
/
movieposterfind.py
37 lines (28 loc) · 1.03 KB
/
movieposterfind.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
### As of now you just need to change the query and youll get a image-url from
### bing_search
import urllib
import urllib2
import json
def main():
movie = "harry potter"
query = movie + " site:movieposter.com"
print (query)
#print bing_search(query, 'Web'
def bing_search(query):
search_type = 'Image'
key= 'OnxQM0p1rgGWyKf5ShtHvpVuClj3eJcPVNENs1dzo8I'
query = urllib.quote(query)
# create credential for authentication
credentials = (':%s' % key).encode('base64')[:-1]
auth = 'Basic %s' % credentials
url = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/'+search_type+'?Query=%27'+query+'%27&$top=5&$format=json'
request = urllib2.Request(url)
request.add_header('Authorization', auth)
request_opener = urllib2.build_opener()
response = request_opener.open(request)
response_data = response.read()
json_result = json.loads(response_data)
result_list = json_result['d']['results']
return result_list[0]['MediaUrl']
if __name__ == "__main__":
main()