antfraia commited on
Commit
e6ac219
·
1 Parent(s): b1d35e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -37
app.py CHANGED
@@ -1,66 +1,56 @@
1
  import streamlit as st
 
2
  from apify_client import ApifyClient
3
  import requests
4
- import pandas as pd
5
 
 
6
  def fetch_google_maps_info(website_name):
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[0] if items else None
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
  google_maps_data = fetch_google_maps_info(website_name)
33
 
34
  if google_maps_data:
35
- # Formatting and displaying all the data in Streamlit table
36
- table_data = {}
37
- for key, value in google_maps_data.items():
38
- # Handle lists of strings
39
- if isinstance(value, list) and all(isinstance(item, str) for item in value):
40
- table_data[key] = ", ".join(value)
41
- # Handle lists of dictionaries
42
- elif isinstance(value, list) and all(isinstance(item, dict) for item in value):
43
- table_data[key] = ", ".join([str(item) for item in value])
44
- # Handle nested dictionaries
45
- elif isinstance(value, dict):
46
- table_data[key] = ", ".join([f"{k}: {v}" for k, v in value.items()])
47
- else:
48
- table_data[key] = value
49
-
50
- st.table(table_data)
51
-
52
- # Fetch weather info based on Google Maps data's location
53
  lat = google_maps_data["location"]["lat"]
54
  lng = google_maps_data["location"]["lng"]
55
-
56
  if lat and lng:
57
- # Display location on Streamlit map
58
- df_location = pd.DataFrame({'lat': [lat], 'lon': [lng]})
59
- st.map(df_location)
60
-
61
  weather_data = fetch_weather_info(lat, lng)
62
  current_weather = weather_data.get("current", {})
63
- st.write(f"Temperature: {current_weather.get('temp')}°C")
64
- st.write(f"Weather: {current_weather.get('weather')[0].get('description')}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  else:
66
  st.write("No results found for this website / company name on Google Maps.")
 
1
  import streamlit as st
2
+ import pandas as pd
3
  from apify_client import ApifyClient
4
  import requests
 
5
 
6
+ # Function to fetch Google Maps info
7
  def fetch_google_maps_info(website_name):
8
  apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
9
+ run_input = {"searchStringsArray": [website_name]}
 
 
 
 
 
 
 
10
  run = apify_client.actor("nwua9Gu5YrADL7ZDj").call(run_input=run_input)
 
 
11
  items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
12
  return items[0] if items else None
13
 
14
+ # Function to fetch weather info
15
  def fetch_weather_info(lat, lon):
16
  API_KEY = "91b23cab82ee530b2052c8757e343b0d"
17
  url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=hourly,daily&appid={API_KEY}"
18
  response = requests.get(url)
19
  return response.json()
20
 
21
+ # Streamlit app
22
+ st.title("Data Visualization")
23
+
24
  website_name = st.text_input("Enter a website / company name:")
25
 
26
  if website_name:
27
  google_maps_data = fetch_google_maps_info(website_name)
28
 
29
  if google_maps_data:
30
+ # Display location and fetch weather info
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  lat = google_maps_data["location"]["lat"]
32
  lng = google_maps_data["location"]["lng"]
 
33
  if lat and lng:
 
 
 
 
34
  weather_data = fetch_weather_info(lat, lng)
35
  current_weather = weather_data.get("current", {})
36
+ st.write(f"**Location:** {lat}, {lng}")
37
+ st.write(f"**Temperature:** {current_weather.get('temp')}°C")
38
+ st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
39
+
40
+ # Display occupancy chart
41
+ st.subheader("Occupancy Data")
42
+ df_occupancy = pd.DataFrame()
43
+ for day, day_data in occupancy_data.items():
44
+ if day_data:
45
+ hours = [entry['hour'] for entry in day_data]
46
+ occupancy = [entry['occupancyPercent'] for entry in day_data]
47
+ df_occupancy[day] = pd.Series(occupancy, index=hours)
48
+ st.line_chart(df_occupancy, use_container_width=True)
49
+
50
+ # Display reviews data
51
+ st.subheader("Reviews Data")
52
+ st.write(f"Total Reviews Count: {reviews_data['reviewsCount']}")
53
+ df_reviews = pd.DataFrame(list(reviews_data['reviewsDistribution'].items()), columns=['Review', 'Count'])
54
+ st.bar_chart(df_reviews.set_index('Review'))
55
  else:
56
  st.write("No results found for this website / company name on Google Maps.")