Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,90 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
import requests
|
| 5 |
|
| 6 |
-
# Function to fetch
|
| 7 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
response = requests.get(url)
|
| 9 |
return response.json()
|
| 10 |
|
| 11 |
# Streamlit app
|
| 12 |
st.title("Data Visualization")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
google_maps_data =
|
| 18 |
-
|
| 19 |
-
if google_maps_data:
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
else:
|
| 41 |
-
st.write("No
|
| 42 |
-
else:
|
| 43 |
-
st.write("No results found.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
from apify_client import ApifyClient
|
| 5 |
import requests
|
| 6 |
|
| 7 |
+
# Function to fetch Google Maps info
|
| 8 |
+
def fetch_google_maps_info(website_name):
|
| 9 |
+
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
| 10 |
+
run_input = {"searchStringsArray": [website_name]}
|
| 11 |
+
run = apify_client.actor("nwua9Gu5YrADL7ZDj").call(run_input=run_input)
|
| 12 |
+
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
| 13 |
+
return items[0] if items else None
|
| 14 |
+
|
| 15 |
+
# Function to fetch website content using Apify actor
|
| 16 |
+
def fetch_website_content(website_url):
|
| 17 |
+
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
|
| 18 |
+
run_input = {"startUrls": [website_url]}
|
| 19 |
+
run = apify_client.actor("moJRLRc85AitArpNN").call(run_input=run_input)
|
| 20 |
+
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
|
| 21 |
+
return items[0] if items else None
|
| 22 |
+
|
| 23 |
+
# Function to fetch weather info
|
| 24 |
+
def fetch_weather_info(lat, lon):
|
| 25 |
+
API_KEY = "91b23cab82ee530b2052c8757e343b0d"
|
| 26 |
+
url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={API_KEY}"
|
| 27 |
response = requests.get(url)
|
| 28 |
return response.json()
|
| 29 |
|
| 30 |
# Streamlit app
|
| 31 |
st.title("Data Visualization")
|
| 32 |
|
| 33 |
+
website_name = st.text_input("Enter a website / company name:")
|
| 34 |
+
|
| 35 |
+
if website_name:
|
| 36 |
+
google_maps_data = fetch_google_maps_info(website_name)
|
| 37 |
+
|
| 38 |
+
if google_maps_data:
|
| 39 |
+
# Display website link in a specific output box
|
| 40 |
+
website_link = google_maps_data.get('website')
|
| 41 |
+
st.text_area("Website Link:", website_link)
|
| 42 |
+
|
| 43 |
+
# Fetch and display website content
|
| 44 |
+
website_content = fetch_website_content(website_link)
|
| 45 |
+
if website_content:
|
| 46 |
+
st.subheader("Scraped Website Content")
|
| 47 |
+
content_df = pd.DataFrame(website_content)
|
| 48 |
+
st.table(content_df)
|
| 49 |
+
|
| 50 |
+
# Display location and fetch weather info
|
| 51 |
+
lat = google_maps_data["location"]["lat"]
|
| 52 |
+
lng = google_maps_data["location"]["lng"]
|
| 53 |
+
if lat and lng:
|
| 54 |
+
st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]})) # Display the map
|
| 55 |
+
weather_data = fetch_weather_info(lat, lng)
|
| 56 |
+
current_weather = weather_data.get("current", {})
|
| 57 |
+
temp_in_celsius = current_weather.get('temp') - 273.15
|
| 58 |
+
st.write(f"**Location:** {lat}, {lng}")
|
| 59 |
+
st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
|
| 60 |
+
st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
|
| 61 |
+
|
| 62 |
+
# Occupancy Data
|
| 63 |
+
st.subheader("Occupancy Data")
|
| 64 |
+
occupancy_data = google_maps_data.get('popularTimesHistogram', {})
|
| 65 |
+
for day, day_data in occupancy_data.items():
|
| 66 |
+
if day_data:
|
| 67 |
+
hours = [entry['hour'] for entry in day_data]
|
| 68 |
+
occupancy = [entry['occupancyPercent'] for entry in day_data]
|
| 69 |
+
st.write(day)
|
| 70 |
+
st.bar_chart(pd.Series(occupancy, index=hours), use_container_width=True)
|
| 71 |
+
|
| 72 |
+
# Review Count and Distribution
|
| 73 |
+
st.subheader("Review Count and Distribution")
|
| 74 |
+
st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
|
| 75 |
+
review_distribution = google_maps_data['reviewsDistribution']
|
| 76 |
+
days_order = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
|
| 77 |
+
ordered_distribution = {day: review_distribution.get(day, 0) for day in days_order}
|
| 78 |
+
st.bar_chart(pd.Series(ordered_distribution), use_container_width=True)
|
| 79 |
+
|
| 80 |
+
# Reviews Table
|
| 81 |
+
st.subheader("Customer Reviews")
|
| 82 |
+
reviews = google_maps_data.get('reviews', [])
|
| 83 |
+
if reviews:
|
| 84 |
+
review_df = pd.DataFrame(reviews)
|
| 85 |
+
st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
|
| 86 |
+
else:
|
| 87 |
+
st.write("No reviews available.")
|
| 88 |
+
|
| 89 |
else:
|
| 90 |
+
st.write("No results found for this website / company name on Google Maps.")
|
|
|
|
|
|