antfraia commited on
Commit
95f9e66
·
1 Parent(s): 2a7094d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
- from serpapi import GoogleSearch
 
3
 
4
  def fetch_google_maps_results(query=None, search_type="search"):
5
  if not query:
@@ -14,25 +15,19 @@ def fetch_google_maps_results(query=None, search_type="search"):
14
  "q": query
15
  }
16
 
 
 
17
 
 
18
 
19
-
20
-
21
-
22
- search = GoogleSearch(params)
23
- results = search.get_dict()
24
- return results
25
 
26
  st.title("Google Maps API Search via SerpAPI")
27
  st.write("Enter a search query to fetch results from Google Maps.")
28
 
29
  # Input field
30
-
31
  query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
32
 
33
-
34
-
35
-
36
  # Button to trigger the API call
37
  if st.button("Search"):
38
  if not query:
@@ -40,6 +35,19 @@ if st.button("Search"):
40
  else:
41
  try:
42
  results = fetch_google_maps_results(query=query)
43
- st.write(results) # Display the results
44
- except Exception as e:
45
- st.error(f"Couldn't fetch the results. Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import requests
3
+ from requests.exceptions import HTTPError
4
 
5
  def fetch_google_maps_results(query=None, search_type="search"):
6
  if not query:
 
15
  "q": query
16
  }
17
 
18
+ response = requests.get("https://serpapi.com/search", params=params)
19
+ response.raise_for_status() # Raise HTTPError for bad response
20
 
21
+ jsonResponse = response.json() # Parse JSON content
22
 
23
+ return jsonResponse
 
 
 
 
 
24
 
25
  st.title("Google Maps API Search via SerpAPI")
26
  st.write("Enter a search query to fetch results from Google Maps.")
27
 
28
  # Input field
 
29
  query = st.text_input("Search Query (q): (Use for regular Google Maps search)")
30
 
 
 
 
31
  # Button to trigger the API call
32
  if st.button("Search"):
33
  if not query:
 
35
  else:
36
  try:
37
  results = fetch_google_maps_results(query=query)
38
+ # Display user reviews
39
+ user_reviews = results.get("user_reviews", [])
40
+ if user_reviews:
41
+ st.write("User Reviews:")
42
+ for review in user_reviews:
43
+ st.write("Username:", review["username"])
44
+ st.write("Rating:", review["rating"])
45
+ st.write("Description:", review["description"])
46
+ st.write("Date:", review["date"])
47
+ st.write("---")
48
+ else:
49
+ st.write("No user reviews found.")
50
+ except HTTPError as http_err:
51
+ st.error(f'HTTP error occurred: {http_err}')
52
+ except Exception as err:
53
+ st.error(f'Other error occurred: {err}')