Example #1
0
def handle_movie_choice(choice, results):

    if choice >= "1" and choice <= "5":
        synopsis(int(choice) - 1, results)

    else:
        ui.print_to_user("Please enter a valid selection")
Example #2
0
def main():
    log.write_to_log("Main function executed.")

    ui.print_to_user("\nWelcome to Fun Night Out!")

    quit = "q"
    choice = None

    # main menu display loop
    while choice != quit:
        choice = ui.display_menu()
        handle_choice(choice)
Example #3
0
def handle_choice(choice):

    if choice == "1":
        restaurants.food_start()

    elif choice == "2":
        DBmovie.movie_start()

    elif choice == "q" or choice == "Q":
        ui.print_to_user("\nGoodbye!\n")
        # close log file
        log.close_file()
        exit(0)

    else:
        ui.print_to_user("Please enter a valid selection")
Example #4
0
def print_restaurant(json_obj):
    # hopping through the json_obj and printing the necessary information
    for item in json_obj["restaurants"]:
        restaurant = item["restaurant"]
        location = restaurant["location"]
        ui.print_to_user("\nName: " + restaurant["name"])
        ui.print_to_user("Tags: " + restaurant["cuisines"])
        ui.print_to_user("$ for 2: " +
                         str(restaurant["average_cost_for_two"]) + "$")
        ui.print_to_user("Address: " + location["address"] + "\n")
Example #5
0
def print_movie_list(response):
    count = 0
    ui.print_to_user("")
    for i in response['results']:
        if count >= 5:
            break
        count += 1
        ui.print_to_user(str(count) + ". " + i['title'])
    ui.print_to_user('b. back')
    ui.print_to_user("")
Example #6
0
def movie_start():

    ui.print_to_user("\n*Top 5 movies in Twin Cities Area Theaters*")
    results = movie_api_top_5_movies_request()
    # log response status code
    log.write_to_log("Status code for request to Movie API: " + str(results))
    json_obj = convert_to_json(results)

    quit = "b"
    choice = None

    while choice != quit:
        print_movie_list(json_obj)
        choice = pick_movie()
        handle_movie_choice(choice, json_obj)

    ui.print_to_user("\n*Main Menu")
    log.write_to_log("Back to main menu.")
Example #7
0
def movie_api_top_5_movies_request():
    url = "https://api.themoviedb.org/3/movie/now_playing"
    key = os.environ.get("MOVIE_KEY")
    country = 'US'
    payload = {'api_key': key, 'region': country}
    response = requests.get(url, payload)

    # error handling for bad API key
    if str(response) == "<Response [401]>":
        ui.print_to_user("\nInvalid API key. Exiting Fun Night Out.\n")
        log.write_to_log("Bad Movie API key, exiting program.")
        exit(0)

    # return data if response 200 (valid API key, working response)
    elif str(response) == "<Response [200]>":
        # return response
        return response

    # handles all other status codes from API request.
    else:
        ui.print_to_user("\nStatus code: " + str(response))
        ui.print_to_user(
            "An unknown error occured with the Movie API. Exiting Fun Night Out.\n"
        )
        log.write_to_log("Unknown error with Movie API. " + str(response))
        exit(0)
Example #8
0
def food_start():

    # var used for storing count number of current restaurant from API call
    restaurant_id = 0
    # init choice to "y"
    choice = "y"
    ui.print_to_user("\n*Restaraunts in the Twin Cities Area*")
    # while loop prompting user if they want info on other restaurants
    while choice != "n":
        if choice == "y":
            response = zomato_request(restaurant_id)
            json_obj = convert_to_json(response)
            print_restaurant(json_obj)
            choice = ui.prompt_for_more()
            restaurant_id += 1
        else:
            ui.print_to_user("Please enter y or n:\n")
            choice = ui.prompt_for_more()
            continue
    ui.print_to_user("\n*Main Menu*")
    log.write_to_log("Back to main menu.")
Example #9
0
def zomato_request(restaurant_id):
    # api key for zomato
    zomato_api = os.environ.get("FOOD_KEY")
    # base url for requests in the Twin Cities area
    base_url = "https://developers.zomato.com/api/v2.1/search?entity_id=826&entity_type=city"
    # header for api request
    header = {
        "User-agent": "curl/7.43.0",
        "Accept": "application/json",
        "user_key": zomato_api
    }
    # adds on to base_url to create new query with start position passed in and count of 1
    url = base_url + "&start=" + str(restaurant_id) + "&count=1"
    # raw_data from API request
    raw_data = requests.get(url, headers=header)
    # log response status code
    log.write_to_log("Status code for request to Zomato API: " + str(raw_data))

    # error handling for bad API key
    if str(raw_data) == "<Response [403]>":
        ui.print_to_user("\nInvalid API key. Exiting Fun Night Out.\n")
        log.write_to_log("Bad Zomato API key, exiting program.")
        exit(0)

    # return data if response 200 (valid API key, working response)
    elif str(raw_data) == "<Response [200]>":
        # return raw_data
        return raw_data

    # handles all other status codes from API request.
    else:
        ui.print_to_user("\nStatus code: " + str(raw_data))
        ui.print_to_user(
            "An unknown error occured with the Zomato API. Exiting Fun Night Out.\n"
        )
        log.write_to_log("Unknown error with the Zomato API. " + str(raw_data))
Example #10
0
def synopsis(which_movie_number, response):
    result_for_number = response['results'][which_movie_number]

    ui.print_to_user('\nMovie:')
    ui.print_to_user(result_for_number["title"])
    ui.print_to_user('\nRelease date:')
    ui.print_to_user(result_for_number["release_date"])
    ui.print_to_user('\nSynopsis:')
    ui.print_to_user(result_for_number['overview'])