Pijush2023 commited on
Commit
2574bc4
·
verified ·
1 Parent(s): 22c5b4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -968,19 +968,13 @@ def fetch_yelp_restaurants():
968
  from serpapi.google_search import GoogleSearch
969
  from datetime import datetime, timedelta
970
 
971
- def fetch_hotels_birmingham():
972
- current_date = datetime.now().strftime("%Y-%m-%d")
973
-
974
- # Define the parameters for the Google Hotels API request
975
  params = {
976
  "engine": "google_hotels",
977
- "q": "Birmingham,AL",
978
  "check_in_date": "2024-08-14",
979
  "check_out_date": "2024-08-15",
980
- "vacation_rentals": "false",
981
- # "amenities": (2,4,10,15,16,20,21,24,29,32),
982
- "rating": (7,8,9),
983
- "hotel_class": (2,3,4,5),
984
  "currency": "USD",
985
  "gl": "us",
986
  "hl": "en",
@@ -991,12 +985,14 @@ def fetch_hotels_birmingham():
991
  search = GoogleSearch(params)
992
  results = search.get_dict()
993
 
994
- # Debugging: Print the results to ensure the API call is working
995
- print("API Response:", results)
996
-
997
  # Extract the hotel results from the response
998
  hotels = results.get("hotels_results", [])
999
 
 
 
 
 
 
1000
  def star_rating(rating):
1001
  # Convert the rating to a star format with half-stars if necessary
1002
  full_stars = int(float(rating))
@@ -1007,26 +1003,24 @@ def fetch_hotels_birmingham():
1007
 
1008
  response_text = ""
1009
 
1010
- # Iterate through the top 5 hotels and format the response
1011
- for hotel in hotels[:5]:
1012
  name = hotel.get("title", "No name")
1013
  rating = hotel.get("rating", "No rating")
1014
  reviews = hotel.get("reviews", "No reviews")
1015
- location = f"{name}, Birmingham, AL"
1016
  price = hotel.get("price", "Price not available")
1017
  link = hotel.get("link", "#")
1018
- hotel_class = hotel.get("hotel_class", "Not available")
1019
- # amenities = hotel.get("amenities", "Amenities not available")
1020
 
1021
  if isinstance(amenities, list):
1022
  amenities = ", ".join(amenities)
1023
 
1024
- # Format the output for each hotel
1025
  response_text += f"[{name}]({link})\n" # Name with clickable link
1026
- response_text += f"*{location}*\n" # Location with hotel name and "Birmingham, AL"
1027
  response_text += f"**Price:** {price}\n"
1028
- response_text += f"**Hotel Class:** {hotel_class} stars\n"
1029
- # response_text += f"**Amenities:** {amenities}\n"
1030
  response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
1031
  response_text += "-" * 50 + "\n"
1032
 
 
968
  from serpapi.google_search import GoogleSearch
969
  from datetime import datetime, timedelta
970
 
971
+ def fetch_birmingham_resorts():
 
 
 
972
  params = {
973
  "engine": "google_hotels",
974
+ "q": "Birmingham Resorts,AL",
975
  "check_in_date": "2024-08-14",
976
  "check_out_date": "2024-08-15",
977
+ "adults": "2",
 
 
 
978
  "currency": "USD",
979
  "gl": "us",
980
  "hl": "en",
 
985
  search = GoogleSearch(params)
986
  results = search.get_dict()
987
 
 
 
 
988
  # Extract the hotel results from the response
989
  hotels = results.get("hotels_results", [])
990
 
991
+ # Check if any hotels were found
992
+ if not hotels:
993
+ print("No resorts found in the response.")
994
+ return "No resort information available."
995
+
996
  def star_rating(rating):
997
  # Convert the rating to a star format with half-stars if necessary
998
  full_stars = int(float(rating))
 
1003
 
1004
  response_text = ""
1005
 
1006
+ # Iterate through the top 5 resorts and format the response
1007
+ for hotel in hotels[:5]: # Limiting to top 5 resorts
1008
  name = hotel.get("title", "No name")
1009
  rating = hotel.get("rating", "No rating")
1010
  reviews = hotel.get("reviews", "No reviews")
1011
+ location = f"{name}, Bali"
1012
  price = hotel.get("price", "Price not available")
1013
  link = hotel.get("link", "#")
1014
+ amenities = hotel.get("amenities", "Amenities not available")
 
1015
 
1016
  if isinstance(amenities, list):
1017
  amenities = ", ".join(amenities)
1018
 
1019
+ # Format the output for each resort
1020
  response_text += f"[{name}]({link})\n" # Name with clickable link
1021
+ response_text += f"*{location}*\n" # Location with resort name and "Bali"
1022
  response_text += f"**Price:** {price}\n"
1023
+ response_text += f"**Amenities:** {amenities}\n"
 
1024
  response_text += f"**Rating:** {star_rating(rating)} ({rating} stars, {reviews} reviews)\n"
1025
  response_text += "-" * 50 + "\n"
1026