antfraia commited on
Commit
932e360
·
1 Parent(s): 01a3765

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -38
app.py CHANGED
@@ -1,40 +1,56 @@
1
  import streamlit as st
2
  from apify_client import ApifyClient
3
-
4
- # Initialize the ApifyClient with your API token
5
- client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
6
-
7
- # Streamlit UI
8
- st.title("Places Information")
9
-
10
- website_name = st.text_input("Enter the type of place (e.g., restaurant, cafe):", "restaurant")
11
- location = st.text_input("Enter the location:", "New York, USA")
12
- button = st.button("Fetch Information")
13
-
14
-
15
- def fetch_places_from_google_maps(website_name, location):
16
- try:
17
- run_input = {
18
- "searchStringsArray": [website_name],
19
- "locationQuery": location,
20
- "maxCrawledPlacesPerSearch": 1, # Fetching only one record for simplicity
21
- # Other input parameters can be added as per your requirements
22
- }
23
-
24
- # Update the actor call
25
- run = client.actor("compass~crawler-google-places").call(run_input=run_input)
26
-
27
- items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
28
- if items:
29
- return items[0]
30
- except Exception as e:
31
- st.write(f"Error: {str(e)}")
32
- return None
33
-
34
-
35
- if button:
36
- place_data = fetch_places_from_google_maps(website_name, location)
37
- if place_data:
38
- st.write(place_data)
39
- else:
40
- st.write("No data found!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from apify_client import ApifyClient
3
+ import requests
4
+
5
+ # API Keys
6
+ APIFY_KEY = 'apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp'
7
+ WEATHER_KEY = '91b23cab82ee530b2052c8757e343b0d'
8
+
9
+ # Set up clients
10
+ apify_client = ApifyClient(APIFY_KEY)
11
+
12
+ st.title("Comprehensive Place Summary App")
13
+ website_name = st.text_input("Enter website / company name:")
14
+
15
+ # 1. Website API Integration (if needed in the future)
16
+ def fetch_website_content(website_name):
17
+ run = apify_client.actor("mc9KJTQJg3zfQpANg/aYG0l9s7dbB7j3gbS").call(run_input={})
18
+ items = [item for item in apify_client.dataset(run["defaultDatasetId"]).iterate_items()]
19
+ return items
20
+
21
+ # 2. Google Maps API Integration
22
+ def fetch_google_maps_info(website_name):
23
+ run_input = {
24
+ "searchStringsArray": [website_name],
25
+ "locationQuery": "New York, USA",
26
+ #... other parameters you've mentioned
27
+ }
28
+ run = apify_client.actor("mc9KJTQJg3zfQpANg/nwua9Gu5YrADL7ZDj").call(run_input=run_input)
29
+ items = [item for item in apify_client.dataset(run["defaultDatasetId"]).iterate_items()]
30
+ return items
31
+
32
+ # 3. Weather API Integration
33
+ def fetch_weather_data(lat, lon):
34
+ url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&appid={WEATHER_KEY}"
35
+ response = requests.get(url)
36
+ data = response.json()
37
+ return data
38
+
39
+ if website_name:
40
+ google_maps_data = fetch_google_maps_info(website_name)
41
+
42
+ # Presenting Google Maps data in a Streamlit table
43
+ st.subheader("Google Maps Data:")
44
+ st.table(google_maps_data)
45
+
46
+ # Extracting lat and lon and fetching weather data
47
+ lat, lon = google_maps_data[0]['location']['lat'], google_maps_data[0]['location']['lon']
48
+ weather_data = fetch_weather_data(lat, lon)
49
+
50
+ # Display the fetched weather data
51
+ st.subheader("Weather Data:")
52
+ st.write(weather_data['current']) # Displaying current weather data, but you can format this as needed.
53
+
54
+ # Displaying the place location on a Streamlit map
55
+ st.subheader("Place Location:")
56
+ st.map({"lat": lat, "lon": lon})