Skip to content

Commit

Permalink
Merge pull request #23 from rubben-88/main
Browse files Browse the repository at this point in the history
final updates
  • Loading branch information
rubben-88 authored Dec 11, 2024
2 parents e8b7c44 + 057682b commit 48e31ef
Show file tree
Hide file tree
Showing 12 changed files with 47,991 additions and 48 deletions.
34 changes: 24 additions & 10 deletions backend/app/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def query_ticketmaster(city: str, date: datetime.date, keywords: list[str]) -> l
"""Fetch events from Ticketmaster API."""

date, end_date = get_start_end_date(datetime.combine(date, datetime.min.time()))
print(f"Querying Ticketmaster: city={city}, date={date}, endDate={end_date}, keywords={keywords}")
print(f"""Querying Ticketmaster for:
city={city},
date={date},
endDate={end_date},
keywords={keywords}""")

params = {
"keyword": " ".join(keywords),
Expand All @@ -79,6 +83,7 @@ def query_ticketmaster(city: str, date: datetime.date, keywords: list[str]) -> l

# Parse event data
events_data = response.json().get("_embedded", {}).get("events", [])
print(f"Ticketmaster events found: {len(events_data)}")
events = []

for event_data in events_data:
Expand All @@ -88,30 +93,39 @@ def query_ticketmaster(city: str, date: datetime.date, keywords: list[str]) -> l
location=city, # Event location set to the input city
url=event_data.get("url"),
date=event_data["dates"]["start"]["localDate"],
category = event_data.get("classifications", [])[0].get("segment", {}).get("name", "Unknown Category")
category = event_data.get("classifications", [])[0].get("segment", {}).get("name", "Unknown Category"),
priority = 4 # priority 4 means higher than static events
)
events.append(event)

return events

def check_pinned_events(city: str = None, date: datetime.date = None, keywords: list[str] = None):
"""Check for pinned events and locations matching the given city, date, and keywords."""

#print(f"---Checking pinned for city: {city.lower()}, date: {date} and keywords: {keywords}")
return_events = []

# Check in pinned events
with open(PINNED_EVENTS_PATH, 'r', encoding='utf-8') as events_file:
pinned_events = json.load(events_file).get('pinned_events', [])
for event in pinned_events:
#print(f"---pinned with location: {event['location'].lower()}, date: {parse_date(event['date'])} and category: {event.get('category', '').lower()}")
if (
(city is None or event['location'].lower() == city.lower()) and
(date is None or parse_date(event['date']) == date) and
(keywords is None or any(keyword.lower() in event.get('category', '').lower() for keyword in keywords))
(date is None or event['date'] is None or parse_date(event['date']) == date) and
(len(keywords)==0 or event['category'] is None or any(keyword.lower() in event['category'].lower() for keyword in keywords))
):
return {"type": "event", "data": event}
basemodel_event = Event(**event)
return_events.append(basemodel_event)
#return {"type": "event", "data": event}
return return_events

# Check in pinned locations
with open(PINNED_LOCATIONS_PATH, 'r', encoding='utf-8') as locations_file:
pinned_locations = json.load(locations_file).get('pinned_locations', [])
for location in pinned_locations:
if city is None or location['city'].lower() == city.lower():
return {"type": "location", "data": location}
#with open(PINNED_LOCATIONS_PATH, 'r', encoding='utf-8') as locations_file:
# pinned_locations = json.load(locations_file).get('pinned_locations', [])
# for location in pinned_locations:
# if city is None or location['city'].lower() == city.lower():
# return {"type": "location", "data": location}

return None
6 changes: 5 additions & 1 deletion backend/app/api/lmstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class Message(TypedDict):
def lm_studio_request(message: Answer) -> str:
full_url = f"http://{LMSTUDIO_HOST}/{LMSTUDIO_ENDPOINT}"


#ROLE = "You are application assistant. Based on given JSON tell what person can visit. Answer in human way like chat assistant talking to a person."
ROLE = "The input is JSON data about a city. Give a summary about all these events (still to happen) in order with a human feel to it, formulated mostly as continuous text. Do not mention you are making a summary."

messages = [
{ "role": "system", "content": "You are application assistant. Based on given JSON tell what person can visit. Answer in human way like chat assistant talking to a person." },
{ "role": "system", "content": ROLE },
{ "role": "user", "content": str(message) }
]

Expand Down
6 changes: 5 additions & 1 deletion backend/app/api/opentripmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def query_opentripmap(query: OpenTripMapModel):
# PRIORITY
if "rate" in details:
try:
new_event.priority = int(details["rate"])
if (details["rate"][-1] == "h"): # apparantly the '...h' case is the only special case
new_event.priority = int(details["rate"][:-1])
else:
new_event.priority = int(details["rate"])
except:
pass # sometimes the rate is not an integer but for example "3h"
# URL
Expand Down Expand Up @@ -228,6 +231,7 @@ def query_opentripmap(query: OpenTripMapModel):
finally:
new_events.append(new_event)

print(f"Opentripmap events found: {len(new_events)}")
return new_events


Expand Down
8 changes: 6 additions & 2 deletions backend/app/api/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def query_weather(query: WeatherQueryModel):
# Get latitude and longitude for the city
lat, lon = get_lat_lon(query.city)

print(f"Querying weather for: city={query.city}, lat={lat}, lon={lon}, units={query.units}")
print(f"""Querying OpenWeatherMap for:
city={query.city},
lat={lat},
lon={lon},
units={query.units}""")

# Call One Call API with latitude and longitude
query_params = {
Expand All @@ -78,7 +82,7 @@ def query_weather(query: WeatherQueryModel):
}
result = make_request(endpoint=ONE_CALL_API_URL, query_params=query_params)

print(result)
print("Weather info found.")

# Extract current weather data
weather_description = (
Expand Down
9 changes: 9 additions & 0 deletions backend/app/city_checker/citychecker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pandas as pd

df = pd.read_csv('app/city_checker/worldcities.csv')

# to a set for fast lookup
city_set = set(df['city'].str.lower().str.strip())

def is_city(keyword):
return keyword.lower().strip() in city_set
Loading

0 comments on commit 48e31ef

Please sign in to comment.