Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,16 @@ import hashlib
|
|
| 3 |
import datetime
|
| 4 |
import streamlit as st
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Hotelbeds API credentials
|
| 8 |
hotelbeds_api_key = "95ce3e45a02fc6fd9720ecc013a6f674"
|
| 9 |
hotelbeds_api_secret = "785150201f"
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Function to generate the API signature
|
| 12 |
def generate_signature():
|
| 13 |
local_timestamp = int(datetime.datetime.now().timestamp())
|
|
@@ -15,6 +20,19 @@ def generate_signature():
|
|
| 15 |
signature = hashlib.sha256(assemble.encode()).hexdigest()
|
| 16 |
return signature
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Function to make the POST request to the Hotelbeds API and handle pagination
|
| 19 |
def fetch_activities(latitude, longitude, from_date, to_date, language="en", paxes=[{"age": 5}, {"age": 70}], order="DEFAULT"):
|
| 20 |
url = "https://api.test.hotelbeds.com/activity-api/3.0/activities/availability"
|
|
@@ -74,14 +92,16 @@ def fetch_activities(latitude, longitude, from_date, to_date, language="en", pax
|
|
| 74 |
# Streamlit app
|
| 75 |
st.title("Hotelbeds Activity Availability Checker")
|
| 76 |
|
| 77 |
-
|
| 78 |
-
longitude = st.number_input("Longitude", value=-73.93524)
|
| 79 |
from_date = st.date_input("From Date", value=pd.to_datetime("2024-06-20"))
|
| 80 |
to_date = st.date_input("To Date", value=pd.to_datetime("2024-06-24"))
|
| 81 |
|
| 82 |
if st.button("Check Availability"):
|
|
|
|
| 83 |
activities = fetch_activities(latitude, longitude, from_date.isoformat(), to_date.isoformat())
|
| 84 |
if activities:
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
else:
|
| 87 |
st.error("No activities found or an error occurred.")
|
|
|
|
| 3 |
import datetime
|
| 4 |
import streamlit as st
|
| 5 |
import pandas as pd
|
| 6 |
+
import openai
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
# Hotelbeds API credentials
|
| 10 |
hotelbeds_api_key = "95ce3e45a02fc6fd9720ecc013a6f674"
|
| 11 |
hotelbeds_api_secret = "785150201f"
|
| 12 |
|
| 13 |
+
# OpenAI API credentials
|
| 14 |
+
openai.api_key = os.getenv("sk-proj-ai6i8e4j43sJxWlG8y5XT3BlbkFJA7w5uANWtfvRchfBdlgy")
|
| 15 |
+
|
| 16 |
# Function to generate the API signature
|
| 17 |
def generate_signature():
|
| 18 |
local_timestamp = int(datetime.datetime.now().timestamp())
|
|
|
|
| 20 |
signature = hashlib.sha256(assemble.encode()).hexdigest()
|
| 21 |
return signature
|
| 22 |
|
| 23 |
+
# Function to get geo-coordinates from a location name using OpenAI API
|
| 24 |
+
def get_coordinates(location_name):
|
| 25 |
+
prompt = f"Provide the latitude and longitude for {location_name}."
|
| 26 |
+
response = openai.Completion.create(
|
| 27 |
+
engine="text-davinci-003",
|
| 28 |
+
prompt=prompt,
|
| 29 |
+
max_tokens=10,
|
| 30 |
+
temperature=0
|
| 31 |
+
)
|
| 32 |
+
result = response.choices[0].text.strip()
|
| 33 |
+
coordinates = result.split(",")
|
| 34 |
+
return float(coordinates[0]), float(coordinates[1])
|
| 35 |
+
|
| 36 |
# Function to make the POST request to the Hotelbeds API and handle pagination
|
| 37 |
def fetch_activities(latitude, longitude, from_date, to_date, language="en", paxes=[{"age": 5}, {"age": 70}], order="DEFAULT"):
|
| 38 |
url = "https://api.test.hotelbeds.com/activity-api/3.0/activities/availability"
|
|
|
|
| 92 |
# Streamlit app
|
| 93 |
st.title("Hotelbeds Activity Availability Checker")
|
| 94 |
|
| 95 |
+
location_name = st.text_input("Location Name", value="New York City")
|
|
|
|
| 96 |
from_date = st.date_input("From Date", value=pd.to_datetime("2024-06-20"))
|
| 97 |
to_date = st.date_input("To Date", value=pd.to_datetime("2024-06-24"))
|
| 98 |
|
| 99 |
if st.button("Check Availability"):
|
| 100 |
+
latitude, longitude = get_coordinates(location_name)
|
| 101 |
activities = fetch_activities(latitude, longitude, from_date.isoformat(), to_date.isoformat())
|
| 102 |
if activities:
|
| 103 |
+
activity_names = [activity['content']['name'] for activity in activities]
|
| 104 |
+
st.json(activity_names)
|
| 105 |
+
st.write(f"Total number of activities: {len(activity_names)}")
|
| 106 |
else:
|
| 107 |
st.error("No activities found or an error occurred.")
|