-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (35 loc) · 1.22 KB
/
main.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
#!/usr/bin/python
import json
import sys
import requests
import recommendations
def auto_suggest(request):
if request.args and 'query' in request.args:
query = request.args.get('query')
else:
query = "best youtube"
cursorPoint = len(query) + 1
newQuery = "%20".join(query.split())
url = "https://www.google.com/complete/search?q={}%20reddit&cp={}&client=gws-wiz&xssi=t&hl=en&authuser=0&dpr=2".format(
newQuery, cursorPoint)
res = requests.get(url).text[5:]
parsed = json.loads(res)[0]
newResult = [element[0].replace("reddit", "") for element in parsed]
return {"suggest": newResult}, 200, {'Access-Control-Allow-Origin': '*'}
def search(request):
if request.args and 'query' in request.args:
query = request.args.get('query')
else:
query = ""
results = recommendations.get_recommendations(query)
return results, 200, {'Access-Control-Allow-Origin': '*'}
def main():
# assume first argument is query. Default query is 'C++ IDE'
try:
query = sys.argv[1]
except IndexError:
query = "Best C++ IDE"
results = recommendations.get_recommendations(query)
print(results)
if __name__ == "__main__":
main()