Pijush2023 commited on
Commit
3f71a50
·
verified ·
1 Parent(s): e878e84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -1007,14 +1007,14 @@ def fetch_yelp_restaurants():
1007
  results = search.get_dict()
1008
  organic_results = results.get("organic_results", [])
1009
 
1010
- # Start with a header row
1011
- yelp_text = "Top Restaurants in Birmingham, AL:\n"
1012
- yelp_text += "{:<30} {:<10} {:<10} {:<15} {:<40} {:<20}\n".format(
1013
- "Name", "Rating", "Reviews", "Phone", "Snippet", "Services"
1014
- )
1015
- yelp_text += "-"*120 + "\n"
1016
 
1017
- for result in organic_results:
 
 
1018
  name = result.get("title", "No name")
1019
  rating = result.get("rating", "No rating")
1020
  reviews = result.get("reviews", "No reviews")
@@ -1022,16 +1022,18 @@ def fetch_yelp_restaurants():
1022
  snippet = result.get("snippet", "Not Available")
1023
  services = result.get("service_options", "Not Known")
1024
 
1025
- if isinstance(services, list):
1026
- services = ", ".join(services)
1027
- elif isinstance(services, dict):
1028
- services = ", ".join([f"{key}: {value}" for key, value in services.items()])
1029
 
1030
- yelp_text += "{:<30} {:<10} {:<10} {:<15} {:<40} {:<20}\n".format(
1031
- name, rating, reviews, phone, snippet, services
1032
- )
 
 
 
 
 
1033
 
1034
- return yelp_text
1035
 
1036
 
1037
 
 
1007
  results = search.get_dict()
1008
  organic_results = results.get("organic_results", [])
1009
 
1010
+ def star_rating(rating):
1011
+ full_stars = int(float(rating))
1012
+ half_star = 1 if float(rating) - full_stars >= 0.5 else 0
1013
+ return "" * full_stars + "" * (5 - full_stars - half_star)
 
 
1014
 
1015
+ response_text = ""
1016
+
1017
+ for result in organic_results[:5]: # Limiting to top 5 restaurants
1018
  name = result.get("title", "No name")
1019
  rating = result.get("rating", "No rating")
1020
  reviews = result.get("reviews", "No reviews")
 
1022
  snippet = result.get("snippet", "Not Available")
1023
  services = result.get("service_options", "Not Known")
1024
 
1025
+ if isinstance(snippet, list):
1026
+ snippet = " | ".join(snippet[:5]) # Limiting to top 5 snippets
 
 
1027
 
1028
+ # Format the output for each restaurant
1029
+ response_text += f"***{name}***\n" # Name in bold and italic
1030
+ response_text += f"**Contact No:** {phone}\n"
1031
+ response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
1032
+ response_text += f"**Snippet:** {snippet}\n"
1033
+ response_text += "-" * 50 + "\n"
1034
+
1035
+ return response_text
1036
 
 
1037
 
1038
 
1039