antfraia commited on
Commit
d5ff050
·
1 Parent(s): 6b10d9d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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