-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_app.py
37 lines (30 loc) · 1.11 KB
/
function_app.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
import azure.functions as func
import logging
from googlesearch import search
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger")
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
logging.info("Python HTTP trigger function processed a request.")
query = req.params.get("query")
if not query:
try:
req_body = req.get_json()
except ValueError:
pass
else:
query = req_body.get("query")
if query:
results = search(query, num_results=50)
links = []
for link in results:
links.append(link)
linklist = "\n".join(links)
return func.HttpResponse(
linklist
# f"Hello. This HTTP triggered function executed successfully."
)
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a keyword or phrase in the query string or in the request body for a list of Google search results.",
status_code=200,
)