import streamlit as st from apify_client import ApifyClient import requests import pandas as pd 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 all the data in Streamlit table table_data = {} for key, value in google_maps_data.items(): # Handle lists of strings if isinstance(value, list) and all(isinstance(item, str) for item in value): table_data[key] = ", ".join(value) # Handle lists of dictionaries elif isinstance(value, list) and all(isinstance(item, dict) for item in value): table_data[key] = ", ".join([str(item) for item in value]) # Handle nested dictionaries elif isinstance(value, dict): table_data[key] = ", ".join([f"{k}: {v}" for k, v in value.items()]) else: table_data[key] = value 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 df_location = pd.DataFrame({'lat': [lat], 'lon': [lng]}) st.map(df_location) 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.")