PlaceSummary / app.py
antfraia's picture
Update app.py
e6ac219
raw
history blame
2.4 kB
import streamlit as st
import pandas as pd
from apify_client import ApifyClient
import requests
# Function to fetch Google Maps info
def fetch_google_maps_info(website_name):
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
run_input = {"searchStringsArray": [website_name]}
run = apify_client.actor("nwua9Gu5YrADL7ZDj").call(run_input=run_input)
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
return items[0] if items else None
# Function to fetch weather info
def fetch_weather_info(lat, lon):
API_KEY = "91b23cab82ee530b2052c8757e343b0d"
url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={API_KEY}"
response = requests.get(url)
return response.json()
# Streamlit app
st.title("Data Visualization")
website_name = st.text_input("Enter a website / company name:")
if website_name:
google_maps_data = fetch_google_maps_info(website_name)
if google_maps_data:
# Display location and fetch weather info
lat = google_maps_data["location"]["lat"]
lng = google_maps_data["location"]["lng"]
if lat and lng:
weather_data = fetch_weather_info(lat, lng)
current_weather = weather_data.get("current", {})
st.write(f"**Location:** {lat}, {lng}")
st.write(f"**Temperature:** {current_weather.get('temp')}°C")
st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
# Display occupancy chart
st.subheader("Occupancy Data")
df_occupancy = pd.DataFrame()
for day, day_data in occupancy_data.items():
if day_data:
hours = [entry['hour'] for entry in day_data]
occupancy = [entry['occupancyPercent'] for entry in day_data]
df_occupancy[day] = pd.Series(occupancy, index=hours)
st.line_chart(df_occupancy, use_container_width=True)
# Display reviews data
st.subheader("Reviews Data")
st.write(f"Total Reviews Count: {reviews_data['reviewsCount']}")
df_reviews = pd.DataFrame(list(reviews_data['reviewsDistribution'].items()), columns=['Review', 'Count'])
st.bar_chart(df_reviews.set_index('Review'))
else:
st.write("No results found for this website / company name on Google Maps.")