Skip to content

Instantly share code, notes, and snippets.

@JohnsonLuu
Created June 29, 2020 03:01
Show Gist options
  • Save JohnsonLuu/cb54fde9cb5984412b64ff26f76d22af to your computer and use it in GitHub Desktop.
Save JohnsonLuu/cb54fde9cb5984412b64ff26f76d22af to your computer and use it in GitHub Desktop.
Welcome to The Boredless Tourist, an online application giving you the power to find the parts of the city that fit the pace of your life.
We at The Boredless Tourist run a recommendation engine using Python.
We first evaluate what a person’s interests are and then give them recommendations in their area to venues, restaurants, and historical destinations that we think they’ll be engaged by.
destinations = ["Paris, France", "Shanghai, China", "Los Angeles, USA", "São Paulo, Brazil", "Cairo, Egypt"]
test_traveler = ['Erin Wilkes', 'Shanghai, China', ['historical site', 'art']]
def get_destination_index(destination):
destination_index = destinations.index(destination)
return destination_index
print(get_destination_index("Los Angeles, USA"))
print(get_destination_index("Paris, France"))
def get_traveler_location(traveler):
# find the destination string
traveler_destination = traveler[1]
# check the traveler's destination with the list of places
traveler_destination_index = get_destination_index(traveler_destination)
return traveler_destination_index
test_destination_index = get_traveler_location(test_traveler)
print(test_destination_index)
# attractions = [[], [], [], []] or
attractions = [[] for destination in destinations]
print(attractions)
#add an attraction for every destination
def add_attraction(destination, attraction):
try:
destination_index = get_destination_index(destination)
attractions_for_destination = attractions[destination_index].append(attraction)
except ValueError:
print("Error caught!")
# don't need to return anything, this exits function
return
add_attraction("Los Angeles, USA", ["Venice Beach", ["beach"]])
add_attraction("Paris, France", ["the Louvre", ["art", "museum"]])
add_attraction("Paris, France", ["Arc de Triomphe", ["historical site", "monument"]])
add_attraction("Shanghai, China", ["Yu Garden", ["garden", "historcical site"]])
add_attraction("Shanghai, China", ["Yuz Museum", ["art", "museum"]])
add_attraction("Shanghai, China", ["Oriental Pearl Tower", ["skyscraper", "viewing deck"]])
add_attraction("Los Angeles, USA", ["LACMA", ["art", "museum"]])
add_attraction("São Paulo, Brazil", ["São Paulo Zoo", ["zoo"]])
add_attraction("São Paulo, Brazil", ["Pátio do Colégio", ["historical site"]])
add_attraction("Cairo, Egypt", ["Pyramids of Giza", ["monument", "historical site"]])
add_attraction("Cairo, Egypt", ["Egyptian Museum", ["museum"]])
print(attractions)
def find_attractions(destination, interests):
destination_index = get_destination_index(destination)
attractions_in_city = attractions[destination_index]
print(attractions_in_city)
attractions_with_interest = []
# create a for loop to view each attraction in a specified city
for attraction in attractions_in_city:
possible_attraction = attraction
# attraction[0] is the city & country
attraction_tags = attraction[1]
# check if specific attraction matches an interest
for interest in interests:
if interest in attraction_tags:
# only want the name of the attraction
attractions_with_interest.append(possible_attraction[0])
return attractions_with_interest
la_arts = find_attractions("Los Angeles, USA", ['art'])
print(la_arts)
def get_attractions_for_traveler(traveler):
traveler_destination = traveler[1]
traveler_interests = traveler[2]
traveler_attractions = find_attractions(traveler_destination, traveler_interests)
interests_string = "Hi " + traveler[0] + ". we think you'll like these places around " + traveler_destination + ":"
for i in range(len(traveler_attractions)):
# if last attraction in list, use a period
if traveler_attractions[-1] == traveler_attractions[i]:
interests_string += " the " + traveler_attractions[i] + "."
# else, use a comma
else:
interests_string += " the " + traveler_attractions[i] + ", "
return interests_string
smills_france = get_attractions_for_traveler(['Dereck Smill', 'Paris, France', ['monument']])
print(smills_france)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment