antfraia commited on
Commit
2f1d1ae
·
1 Parent(s): 9bfb031

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -42
app.py CHANGED
@@ -1,51 +1,30 @@
1
  import streamlit as st
2
- from serpapi import GoogleSearch
3
 
4
- st.title("Google Maps Reviews Scraper")
 
5
 
6
- # Input fields
7
- query = st.text_input("Enter your search query:")
8
- location = st.text_input("Enter the location (format: latitude,longitude):")
9
- page_number = st.number_input("Page Number (0 for first page)", 0, 100, 0, 20)
10
-
11
- if st.button("Search"):
12
- # Call the function to fetch results
13
- results = fetch_google_maps_results(api_key="b18f4d37042ab8222028830ee1d3db47481ac48f545382eacd7f0469414f1b1a", q=query, ll=location, start=page_number*20)
14
-
15
- # Display the results
16
- if results:
17
- for result in results:
18
- st.write(result['title'])
19
- st.write(result['address'])
20
- st.image(result['thumbnail'])
21
- else:
22
- st.write("No results found.")
23
-
24
-
25
- def fetch_google_maps_results(api_key, q="", ll="", start=0, no_cache=False):
26
- """
27
- Fetch Google Maps results using Serpapi.
28
-
29
- :param api_key: The SerpApi private key.
30
- :param q: The search query.
31
- :param ll: Location as latitude,longitude.
32
- :param start: Result offset for pagination.
33
- :param no_cache: Whether to force fetching fresh results.
34
- :return: List of search results.
35
- """
36
  params = {
37
  "engine": "google_maps",
38
- "q": q,
39
- "ll": ll,
40
- "start": start,
41
- "no_cache": no_cache,
42
- "api_key": api_key,
43
  "output": "json"
44
  }
45
 
46
- search = GoogleSearch(params)
47
- results = search.get_dict()
 
 
 
 
 
 
 
 
 
48
 
49
- # Extracting relevant results
50
- local_results = results.get("local_results", [])
51
- return local_results
 
 
1
  import streamlit as st
2
+ import requests
3
 
4
+ SERPAPI_ENDPOINT = "https://serpapi.com/search"
5
+ API_KEY = "YOUR_API_KEY"
6
 
7
+ def fetch_google_maps_data(query):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  params = {
9
  "engine": "google_maps",
10
+ "q": query,
11
+ "api_key": API_KEY,
 
 
 
12
  "output": "json"
13
  }
14
 
15
+ response = requests.get(SERPAPI_ENDPOINT, params=params)
16
+
17
+ if response.status_code == 200:
18
+ return response.json()
19
+ else:
20
+ st.warning("Failed to fetch data from SerpAPI")
21
+ return None
22
+
23
+ st.title("Google Maps Data Fetcher")
24
+
25
+ query = st.text_input("Enter your query:")
26
 
27
+ if st.button("Search"):
28
+ data = fetch_google_maps_data(query)
29
+ if data:
30
+ st.write(data)