Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,56 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from apify_client import ApifyClient
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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})
|