PlaceSummary / app.py
antfraia's picture
Update app.py
c7f1dd0
raw
history blame
2.57 kB
import streamlit as st
import pandas as pd
from apify_client import ApifyClient
import requests
# Function to fetch Google Maps info using the antonces~gmaps actor
def fetch_google_maps_info(website_name):
apify_client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
run_input = {"searchStringsArray": [website_name]}
run = apify_client.actor("antonces~gmaps").call(run_input=run_input)
items = list(apify_client.dataset(run["defaultDatasetId"]).iterate_items())
return items[0] if items else None
# Function to fetch customer reviews using the new API
def fetch_customer_reviews(location_query):
client = ApifyClient("apify_api_uz0y556N4IG2aLcESj67kmnGSUpHF12XAkLp")
run_input = {
"searchStringsArray": ["restaurant"],
"locationQuery": location_query,
"maxCrawledPlacesPerSearch": 50,
"language": "en",
"maxImages": None,
"onlyDataFromSearchPage": False,
"includeWebResults": False,
"deeperCityScrape": False,
"maxReviews": None,
"oneReviewPerRow": False,
"reviewsSort": "newest",
"reviewsFilterString": "",
"scrapeReviewerName": True,
"scrapeReviewerId": True,
"scrapeReviewerUrl": True,
"scrapeReviewId": True,
"scrapeReviewUrl": True,
"scrapeResponseFromOwnerText": True,
"countryCode": None,
"searchMatching": "all",
"placeMinimumStars": "",
"skipClosedPlaces": False,
"allPlacesNoSearchAction": "",
}
run = client.actor("mc9KJTQJg3zfQpANg/nwua9Gu5YrADL7ZDj").call(run_input=run_input)
return list(client.dataset(run["defaultDatasetId"]).iterate_items())
# Streamlit app for Data Visualization
st.title("Data Visualization")
# Input for website or company name
website_name = st.text_input("Enter a website / company name:")
if website_name:
# Fetch Google Maps data
google_maps_data = fetch_google_maps_info(website_name)
if google_maps_data:
location_query = google_maps_data.get("locationQuery")
reviews_data = fetch_customer_reviews(location_query)
# Display Google Maps data
# ... (use the original display code for Google Maps data here) ...
# Display reviews_data
review_df = pd.DataFrame(reviews_data)
st.subheader("Customer Reviews from New API")
st.table(review_df[['name', 'text', 'publishAt', 'likesCount', 'stars']])
else:
st.write("No results found for this website / company name on Google Maps.")