File size: 2,527 Bytes
3e996d0
ba1946b
932e360
 
 
fce2a17
 
 
932e360
 
fce2a17
932e360
fce2a17
 
 
d1daf4e
fce2a17
 
d1daf4e
932e360
fce2a17
 
 
932e360
fce2a17
 
 
 
932e360
 
 
d1daf4e
fce2a17
d1daf4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fce2a17
d1daf4e
 
 
fce2a17
 
 
d1daf4e
fce2a17
 
 
 
 
 
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
import streamlit as st
from apify_client import ApifyClient
import requests

def fetch_google_maps_info(website_name):
    apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")

    # Prepare the Actor input for Google Maps
    run_input = {
        "searchStringsArray": [website_name],
        # ... other parameters
    }

    # Run the Actor and wait for it to finish
    run = apify_client.actor("nwua9Gu5YrADL7ZDj").call(run_input=run_input)

    # Fetch Actor results from the run's dataset
    items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
    return items[0] if items else None

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()

# Main Streamlit app
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:
        # Formatting and displaying the data in Streamlit table
        table_data = {
            "Location": f"Lat: {google_maps_data['location']['lat']}, Lng: {google_maps_data['location']['lng']}",
            "Plus Code": google_maps_data["plusCode"],
            "Menu": google_maps_data["menu"],
            "Total Score": google_maps_data["totalScore"],
            "Permanently Closed": google_maps_data["permanentlyClosed"],
            "Temporarily Closed": google_maps_data["temporarilyClosed"],
            "Place ID": google_maps_data["placeId"],
            "Categories": ", ".join(google_maps_data["categories"]),
            "CID": google_maps_data["cid"],
            "Reviews Count": google_maps_data["reviewsCount"],
        }

        st.table(table_data)

        # Fetch weather info based on Google Maps data's location
        lat = google_maps_data["location"]["lat"]
        lng = google_maps_data["location"]["lng"]

        if lat and lng:
            # Display location on Streamlit map
            st.map({"lat": lat, "lon": lng})

            weather_data = fetch_weather_info(lat, lng)
            current_weather = weather_data.get("current", {})
            st.write(f"Temperature: {current_weather.get('temp')}°C")
            st.write(f"Weather: {current_weather.get('weather')[0].get('description')}")
    else:
        st.write("No results found for this website / company name on Google Maps.")