forked from raysandeep/FMIYC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevSearch.py
27 lines (22 loc) · 989 Bytes
/
revSearch.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
import requests
import json
textEngineURL = "https://www.googleapis.com/customsearch/v1"
searchKey = "AIzaSyAZnWGGLNprNZLgUJ18VaOiRgHxNQPvMBQ"
textSearchCX = "016220867362134571083:ntcgj0p32rg"
def reverseSearchText(audioTextChunks):
textPieces = []
audioChunksTemp = []
for audioText in audioTextChunks:
audioChunksTemp.append(' '.join([audioText, "what show"]))
audioChunksTemp.append(' '.join([audioText, "what movie"]))
audioTextChunks = audioChunksTemp
for text in audioTextChunks:
response = requests.get(textEngineURL, params={"key":searchKey, "cx":textSearchCX, "q":text})
entries = response.json()['items']
entries = [[entry['title'], entry['snippet']] for entry in entries]
entries = entries[:5]
for entry in entries:
textPieces.append(entry[0].replace('\n', ''))
textPieces.append(entry[1].replace('\n', ''))
print(' '.join(textPieces))
return ' '.join(textPieces)