antfraia commited on
Commit
860b3ba
·
1 Parent(s): 03ea6cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -63
app.py CHANGED
@@ -1,75 +1,43 @@
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 weather info
16
- def fetch_weather_info(lat, lon):
17
- API_KEY = "91b23cab82ee530b2052c8757e343b0d"
18
- url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={API_KEY}"
19
  response = requests.get(url)
20
  return response.json()
21
 
22
  # Streamlit app
23
  st.title("Data Visualization")
24
 
25
- website_name = st.text_input("Enter a website / company name:")
26
-
27
- if website_name:
28
- google_maps_data = fetch_google_maps_info(website_name)
29
-
30
- if google_maps_data:
31
- # Display website link in a specific output box
32
- website_link = google_maps_data.get('website')
33
- st.text_area("Website Link:", website_link)
34
-
35
- # Display location and fetch weather info
36
- lat = google_maps_data["location"]["lat"]
37
- lng = google_maps_data["location"]["lng"]
38
- if lat and lng:
39
- st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]})) # Display the map
40
- weather_data = fetch_weather_info(lat, lng)
41
- current_weather = weather_data.get("current", {})
42
- temp_in_celsius = current_weather.get('temp') - 273.15
43
- st.write(f"**Location:** {lat}, {lng}")
44
- st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
45
- st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
46
-
47
- # Occupancy Data
48
- st.subheader("Occupancy Data")
49
- occupancy_data = google_maps_data.get('popularTimesHistogram', {})
50
- for day, day_data in occupancy_data.items():
51
- if day_data:
52
- hours = [entry['hour'] for entry in day_data]
53
- occupancy = [entry['occupancyPercent'] for entry in day_data]
54
- st.write(day)
55
- st.bar_chart(pd.Series(occupancy, index=hours), use_container_width=True)
56
-
57
- # Review Count and Distribution
58
- st.subheader("Review Count and Distribution")
59
- st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
60
- review_distribution = google_maps_data['reviewsDistribution']
61
- days_order = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
62
- ordered_distribution = {day: review_distribution.get(day, 0) for day in days_order}
63
- st.bar_chart(pd.Series(ordered_distribution), use_container_width=True)
64
-
65
- # Reviews Table
66
- st.subheader("Customer Reviews")
67
- reviews = google_maps_data.get('reviews', [])
68
- if reviews:
69
- review_df = pd.DataFrame(reviews)
70
- st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
71
- else:
72
- st.write("No reviews available.")
73
-
74
  else:
75
- st.write("No results found for this website / company name on Google Maps.")
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import numpy as np
 
4
  import requests
5
 
6
+ # Function to fetch data from the Apify actor
7
+ def fetch_data_from_apify_actor(url):
 
 
 
 
 
 
 
 
 
 
8
  response = requests.get(url)
9
  return response.json()
10
 
11
  # Streamlit app
12
  st.title("Data Visualization")
13
 
14
+ # Fetch data using Apify actor
15
+ apify_actor_url = "https://api.apify.com/v2/actor-runs/HsejBCDbeF39qAgsa?token=apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp"
16
+ data = fetch_data_from_apify_actor(apify_actor_url)
17
+ google_maps_data = data.get('output', {}).get('data', {})
18
+
19
+ if google_maps_data:
20
+ # Display website link in a specific output box
21
+ website_link = google_maps_data.get('website')
22
+ st.text_area("Website Link:", website_link)
23
+
24
+ # Occupancy Data: Aggregate and rank
25
+ st.subheader("Occupancy Data (Aggregated by Day)")
26
+ occupancy_data = google_maps_data.get('popularTimesHistogram', {})
27
+ avg_occupancy = {}
28
+ for day, day_data in occupancy_data.items():
29
+ if day_data:
30
+ avg_occupancy[day] = np.mean([entry['occupancyPercent'] for entry in day_data])
31
+ days_order = sorted(avg_occupancy, key=avg_occupancy.get, reverse=True)
32
+ st.bar_chart(pd.Series({day: avg_occupancy[day] for day in days_order}), use_container_width=True)
33
+
34
+ # Reviews Table
35
+ st.subheader("Customer Reviews")
36
+ reviews = google_maps_data.get('reviews', [])
37
+ if reviews:
38
+ review_df = pd.DataFrame(reviews)
39
+ st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  else:
41
+ st.write("No reviews available.")
42
+ else:
43
+ st.write("No results found.")