antfraia commited on
Commit
036ebf1
·
1 Parent(s): ef76fa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -34
app.py CHANGED
@@ -3,89 +3,90 @@ import pandas as pd
3
  import requests
4
  from apify_client import ApifyClient
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
- # Function to fetch website content
22
  def fetch_website_content(website_url):
23
  apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
24
  run_input = {}
25
- run = apify_client.actor("mc9KJTQJg3zfQpANg/aYG0l9s7dbB7j3gbS").call(run_input=run_input)
26
  items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
27
  return items if items else None
28
 
29
- # Streamlit app
30
  st.title("Data Visualization")
31
 
 
32
  website_name = st.text_input("Enter a website / company name:")
33
 
34
  if website_name:
 
 
 
 
35
  google_maps_data = fetch_google_maps_info(website_name)
 
36
 
37
  if google_maps_data:
38
- # Display website link in a specific output box
39
  website_link = google_maps_data.get('website')
40
  st.text_area("Website Link:", website_link)
41
 
42
  # Display location and fetch weather info
43
  lat = google_maps_data["location"]["lat"]
44
  lng = google_maps_data["location"]["lng"]
45
- if lat and lng:
46
- st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]})) # Display the map
47
- weather_data = fetch_weather_info(lat, lng)
48
- current_weather = weather_data.get("current", {})
49
- temp = current_weather.get('temp')
50
- if temp:
51
- temp_in_celsius = temp - 273.15
52
- st.write(f"**Location:** {lat}, {lng}")
53
- st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
54
- st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
55
 
56
- # Occupancy Data
57
  st.subheader("Occupancy Data")
58
  occupancy_data = google_maps_data.get('popularTimesHistogram', {})
59
  for day, day_data in occupancy_data.items():
60
- if day_data:
61
- hours = [entry['hour'] for entry in day_data]
62
- occupancy = [entry['occupancyPercent'] for entry in day_data]
63
- st.write(day)
64
- st.bar_chart(pd.Series(occupancy, index=hours), use_container_width=True)
65
-
66
- # Review Count and Distribution
67
  st.subheader("Review Count and Distribution")
68
  st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
69
  review_distribution = google_maps_data.get('reviewsDistribution', {})
70
- st.bar_chart(pd.Series(review_distribution), use_container_width=True)
71
 
72
- # Reviews Table
73
  st.subheader("Customer Reviews")
74
  reviews = google_maps_data.get('reviews', [])
75
- if reviews:
76
- review_df = pd.DataFrame(reviews)
77
- st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
78
- else:
79
- st.write("No reviews available.")
80
 
81
- # Website Content
82
  st.subheader("Website Content")
83
  website_content_data = fetch_website_content(website_link)
 
 
84
  if website_content_data:
85
  website_df = pd.DataFrame(website_content_data)
86
  st.table(website_df)
87
  else:
88
  st.write("Unable to retrieve website content.")
89
-
90
  else:
91
  st.write("No results found for this website / company name on Google Maps.")
 
3
  import requests
4
  from apify_client import ApifyClient
5
 
6
+ # Function to fetch Google Maps info using the antonces~gmaps actor
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("antonces~gmaps").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 from OpenWeatherMap API
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
+ # Function to fetch website content using the antonces~web-scraper-task actor
22
  def fetch_website_content(website_url):
23
  apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
24
  run_input = {}
25
+ run = apify_client.actor("antonces~web-scraper-task").call(run_input=run_input)
26
  items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
27
  return items if items else None
28
 
29
+ # Streamlit app for Data Visualization
30
  st.title("Data Visualization")
31
 
32
+ # Input for website or company name
33
  website_name = st.text_input("Enter a website / company name:")
34
 
35
  if website_name:
36
+ # Initialize the progress bar
37
+ progress_bar = st.progress(0)
38
+
39
+ # Fetch Google Maps data
40
  google_maps_data = fetch_google_maps_info(website_name)
41
+ progress_bar.progress(50)
42
 
43
  if google_maps_data:
44
+ # Display website link
45
  website_link = google_maps_data.get('website')
46
  st.text_area("Website Link:", website_link)
47
 
48
  # Display location and fetch weather info
49
  lat = google_maps_data["location"]["lat"]
50
  lng = google_maps_data["location"]["lng"]
51
+ st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]}))
52
+ weather_data = fetch_weather_info(lat, lng)
53
+ current_weather = weather_data.get("current", {})
54
+ temp = current_weather.get('temp')
55
+ temp_in_celsius = temp - 273.15
56
+ st.write(f"**Location:** {lat}, {lng}")
57
+ st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
58
+ st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
 
 
59
 
60
+ # Display Occupancy Data
61
  st.subheader("Occupancy Data")
62
  occupancy_data = google_maps_data.get('popularTimesHistogram', {})
63
  for day, day_data in occupancy_data.items():
64
+ hours = [entry['hour'] for entry in day_data]
65
+ occupancy = [entry['occupancyPercent'] for entry in day_data]
66
+ st.write(day)
67
+ st.bar_chart(pd.Series(occupancy, index=hours))
68
+
69
+ # Display Review Count and Distribution
 
70
  st.subheader("Review Count and Distribution")
71
  st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
72
  review_distribution = google_maps_data.get('reviewsDistribution', {})
73
+ st.bar_chart(pd.Series(review_distribution))
74
 
75
+ # Display Reviews Table
76
  st.subheader("Customer Reviews")
77
  reviews = google_maps_data.get('reviews', [])
78
+ review_df = pd.DataFrame(reviews)
79
+ st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
 
 
 
80
 
81
+ # Fetch and Display Website Content
82
  st.subheader("Website Content")
83
  website_content_data = fetch_website_content(website_link)
84
+ progress_bar.progress(100)
85
+
86
  if website_content_data:
87
  website_df = pd.DataFrame(website_content_data)
88
  st.table(website_df)
89
  else:
90
  st.write("Unable to retrieve website content.")
 
91
  else:
92
  st.write("No results found for this website / company name on Google Maps.")