File size: 3,953 Bytes
3e996d0
e6ac219
eccb5e1
0710745
932e360
 
0710745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
932e360
fce2a17
 
e6ac219
 
 
0710745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fce2a17
0710745
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import streamlit as st
import pandas as pd
import numpy as np
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 website content using Apify actor
def fetch_website_content(website_url):
    apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
    run_input = {"startUrls": [website_url]}
    run = apify_client.actor("moJRLRc85AitArpNN").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 website link in a specific output box
        website_link = google_maps_data.get('website')
        st.text_area("Website Link:", website_link)

        # Fetch and display website content
        website_content = fetch_website_content(website_link)
        if website_content:
            st.subheader("Scraped Website Content")
            content_df = pd.DataFrame(website_content)
            st.table(content_df)

        # Display location and fetch weather info
        lat = google_maps_data["location"]["lat"]
        lng = google_maps_data["location"]["lng"]
        if lat and lng:
            st.map(pd.DataFrame({'lat': [lat], 'lon': [lng]}))  # Display the map
            weather_data = fetch_weather_info(lat, lng)
            current_weather = weather_data.get("current", {})
            temp_in_celsius = current_weather.get('temp') - 273.15
            st.write(f"**Location:** {lat}, {lng}")
            st.write(f"**Temperature:** {temp_in_celsius:.2f}°C")
            st.write(f"**Weather:** {current_weather.get('weather')[0].get('description')}")
        
        # Occupancy Data
        st.subheader("Occupancy Data")
        occupancy_data = google_maps_data.get('popularTimesHistogram', {})
        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]
                st.write(day)
                st.bar_chart(pd.Series(occupancy, index=hours), use_container_width=True)
        
        # Review Count and Distribution
        st.subheader("Review Count and Distribution")
        st.write(f"Total Reviews Count: {google_maps_data['reviewsCount']}")
        review_distribution = google_maps_data['reviewsDistribution']
        days_order = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
        ordered_distribution = {day: review_distribution.get(day, 0) for day in days_order}
        st.bar_chart(pd.Series(ordered_distribution), use_container_width=True)
        
        # Reviews Table
        st.subheader("Customer Reviews")
        reviews = google_maps_data.get('reviews', [])
        if reviews:
            review_df = pd.DataFrame(reviews)
            st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
        else:
            st.write("No reviews available.")

    else:
        st.write("No results found for this website / company name on Google Maps.")