Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ df1 = pd.read_csv(f"https://docs.google.com/spreadsheets/d/{sheet_id}/export?for
|
|
20 |
urls = df1["網址"].tolist()
|
21 |
|
22 |
# Create a DataFrame to store all restaurant data
|
23 |
-
df = pd.DataFrame(columns=["Store Name", "Address", "Latitude", "Longitude", "Region"])
|
24 |
|
25 |
# Initialize Nominatim geocoder
|
26 |
geolocator = Nominatim(user_agent="my_app")
|
@@ -56,6 +56,12 @@ def fetch_data():
|
|
56 |
except AttributeError:
|
57 |
address = None
|
58 |
region = "Unknown"
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
try:
|
61 |
location = geolocator.geocode(address)
|
@@ -72,6 +78,7 @@ def fetch_data():
|
|
72 |
new_row = pd.DataFrame({
|
73 |
"Store Name": [store_name],
|
74 |
"Address": [address],
|
|
|
75 |
"Latitude": [latitude],
|
76 |
"Longitude": [longitude],
|
77 |
"Region": [region]
|
@@ -133,7 +140,7 @@ if st.button("Fetch Restaurant Data"):
|
|
133 |
if pd.notnull(row["Latitude"]) and pd.notnull(row["Longitude"]):
|
134 |
folium.Marker(
|
135 |
location=[row["Latitude"], row["Longitude"]],
|
136 |
-
popup=row[
|
137 |
tooltip=row["Address"]
|
138 |
).add_to(marker_cluster)
|
139 |
|
|
|
20 |
urls = df1["網址"].tolist()
|
21 |
|
22 |
# Create a DataFrame to store all restaurant data
|
23 |
+
df = pd.DataFrame(columns=["Store Name", "Address", "Phone", "Latitude", "Longitude", "Region"])
|
24 |
|
25 |
# Initialize Nominatim geocoder
|
26 |
geolocator = Nominatim(user_agent="my_app")
|
|
|
56 |
except AttributeError:
|
57 |
address = None
|
58 |
region = "Unknown"
|
59 |
+
|
60 |
+
# Try to extract phone number
|
61 |
+
try:
|
62 |
+
phone = soup.find("a", {"data-event": "CTA_tel"}).get("href").replace("tel:", "")
|
63 |
+
except AttributeError:
|
64 |
+
phone = None
|
65 |
|
66 |
try:
|
67 |
location = geolocator.geocode(address)
|
|
|
78 |
new_row = pd.DataFrame({
|
79 |
"Store Name": [store_name],
|
80 |
"Address": [address],
|
81 |
+
"Phone": [phone], # Add phone number to the DataFrame
|
82 |
"Latitude": [latitude],
|
83 |
"Longitude": [longitude],
|
84 |
"Region": [region]
|
|
|
140 |
if pd.notnull(row["Latitude"]) and pd.notnull(row["Longitude"]):
|
141 |
folium.Marker(
|
142 |
location=[row["Latitude"], row["Longitude"]],
|
143 |
+
popup=f"{row['Store Name']} ({row['Phone']})", # Show phone in the popup
|
144 |
tooltip=row["Address"]
|
145 |
).add_to(marker_cluster)
|
146 |
|