Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,55 +2,51 @@ 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 |
-
|
26 |
-
#... other parameters you've mentioned
|
27 |
}
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
return items
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&appid={
|
35 |
response = requests.get(url)
|
36 |
-
|
37 |
-
|
|
|
|
|
38 |
|
39 |
if website_name:
|
|
|
40 |
google_maps_data = fetch_google_maps_info(website_name)
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
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 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from apify_client import ApifyClient
|
3 |
import requests
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def fetch_google_maps_info(website_name):
|
6 |
+
# Initialize the ApifyClient with your API token
|
7 |
+
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
8 |
+
|
9 |
+
# Prepare the Actor input for Google Maps
|
10 |
run_input = {
|
11 |
"searchStringsArray": [website_name],
|
12 |
+
# ... other parameters
|
|
|
13 |
}
|
14 |
+
|
15 |
+
# Run the Actor and wait for it to finish
|
16 |
+
run = apify_client.actor("nwua9Gu5YrADL7ZDj").call(run_input=run_input)
|
17 |
+
|
18 |
+
# Fetch Actor results from the run's dataset
|
19 |
+
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
20 |
return items
|
21 |
|
22 |
+
def fetch_weather_info(lat, lon):
|
23 |
+
API_KEY = "91b23cab82ee530b2052c8757e343b0d"
|
24 |
+
url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={API_KEY}"
|
25 |
response = requests.get(url)
|
26 |
+
return response.json()
|
27 |
+
|
28 |
+
# Main Streamlit app
|
29 |
+
website_name = st.text_input("Enter a website / company name:")
|
30 |
|
31 |
if website_name:
|
32 |
+
# Fetch Google Maps data
|
33 |
google_maps_data = fetch_google_maps_info(website_name)
|
34 |
|
35 |
+
# Display in Streamlit table
|
36 |
+
if google_maps_data:
|
37 |
+
st.write(google_maps_data) # Or customize the table presentation
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
# Fetch weather info based on Google Maps data's location
|
40 |
+
lat = google_maps_data[0].get("location", {}).get("lat")
|
41 |
+
lng = google_maps_data[0].get("location", {}).get("lng")
|
42 |
+
|
43 |
+
if lat and lng:
|
44 |
+
# Display location on Streamlit map
|
45 |
+
st.map({"lat": lat, "lon": lng})
|
46 |
+
|
47 |
+
weather_data = fetch_weather_info(lat, lng)
|
48 |
+
current_weather = weather_data.get("current", {})
|
49 |
+
st.write(f"Temperature: {current_weather.get('temp')}°C")
|
50 |
+
st.write(f"Weather: {current_weather.get('weather')[0].get('description')}")
|
51 |
+
else:
|
52 |
+
st.write("No results found for this website / company name on Google Maps.")
|