Esempio n. 1
0
def match_Business(data):
    parameters = data['queryResult']['parameters']

    # validate request parameters, return an error if there are issues
    error, search_params = validate_params(parameters)
    if error:
        return error

    # create a YelpFusion object which retrieves the business details from YelpFusion API
    try:
        yelpFusion = YelpFusion(search_params)
        response = yelpFusion.matchBusiness()

        reply = build_Multiline_Msg(response)
    # return an error if there is an error getting the forecast
    except (ValueError, IOError) as error:
        return error

    return jsonify(reply)
Esempio n. 2
0
def get_FeaturedEvents(data):
    parameters = data['queryResult']['parameters']

    # validate request parameters, return an error if there are issues
    error, search_params = validate_params(parameters)
    if error:
        return error

    # create a YelpFusion object which retrieves the business details from YelpFusion API
    try:
        yelpFusion = YelpFusion(search_params)
        response = yelpFusion.getFeaturedEvents()

        info = []
        if response:
            address = ", ".join(response["location"]["display_address"])
            eventDate = datetime.strptime(response['time_start'].split("T")[0],
                                          '%Y-%m-%d')
            eventDate = eventDate.strftime('%d-%m-%Y')

            info.append({"text": "Date: " + eventDate, "postback": ""})

            info.append({
                "text": "Get Tickets",
                "postback": response['tickets_url']
            })

            info.append({
                "text": "Visit event site",
                "postback": response['event_site_url']
            })

            reply = build_Card_Msg(response['name'], response['description'],
                                   response['image_url'], info)
        else:
            reply = build_Singleline_Msg("No featured events found")
    # return an error if there is an error getting the forecast
    except (ValueError, IOError) as error:
        return error

    return jsonify(reply)
Esempio n. 3
0
def get_BusinessReviews(data):
    parameters = data['queryResult']['parameters']

    # validate request parameters, return an error if there are issues
    error, search_params = validate_params(parameters)
    if error:
        return error

    # create a YelpFusion object which retrieves the business details from YelpFusion API
    try:
        yelpFusion = YelpFusion(search_params)
        response = yelpFusion.getBusinessReviews()
        reviews = response.get('reviews')
        if (len(reviews) == 0):
            reply = build_Singleline_Msg("No reviews found")
        else:
            reply = build_Multiline_Msg2(reviews)
    # return an error if there is an error getting the forecast
    except (ValueError, IOError) as error:
        return error

    return jsonify(reply)
Esempio n. 4
0
def search_Business(data):
    parameters = data['queryResult']['parameters']

    # validate request parameters, return an error if there are issues
    error, search_params = validate_params(parameters)
    if error:
        return error

    # create a YelpFusion object which retrieves the business details from YelpFusion API
    try:
        yelpFusion = YelpFusion(search_params)
        response = yelpFusion.searchBusiness()
        businesses = response.get('businesses')
        if (businesses is None):
            reply = build_Singleline_Msg("No matching businesses found")
        else:
            reply = build_MultiCard_Msg(businesses)
    # return an error if there is an error getting the forecast
    except (ValueError, IOError) as error:
        return error

    return jsonify(reply)
Esempio n. 5
0
def get_AutocompleteSuggestions(data):
    parameters = data['queryResult']['parameters']

    # validate request parameters, return an error if there are issues
    error, search_params = validate_params(parameters)
    if error:
        return error

    # create a YelpFusion object which retrieves the business details from YelpFusion API
    try:
        yelpFusion = YelpFusion(search_params)
        response = yelpFusion.getAutocompleteSuggestions()
        categories_list = response.get('categories')
        terms_list = response.get('terms')
    # return an error if there is an error getting the forecast
    except (ValueError, IOError) as error:
        return error

    reply = {}
    reply["fulfillmentText"] = categories_list
    reply["fulfillmentMessages"] = []

    return jsonify(reply)
Esempio n. 6
0
def get_Business(data):
    parameters = data['queryResult']['parameters']

    # validate request parameters, return an error if there are issues
    error, search_params = validate_params(parameters)
    if error:
        return error

    # create a YelpFusion object which retrieves the business details from YelpFusion API
    try:
        yelpFusion = YelpFusion(search_params)
        response = yelpFusion.getBusiness()
        if (response.get("error") is None):
            #generateImgMosaic(response['image_url'], response['photos'])
            #uploadImageToGCP(response['name'])
            contact = ", ".join(response["location"]["display_address"]
                                ) + " [" + response["display_phone"] + "]"
            #url = "https://storage.cloud.google.com/yelperassistant.appspot.com/images/{}.jpg".format(response['name'])
            #url = response['image_url']
            url = response['photos'][1]

            #day_map = {0:"Sun", 1:"Mon", 2:"Tue", 3:"Wed", 4:"Thu", 5:"Fri", 6:"Sat"}

            info = []
            operatinghrs_wkday = ""
            operatinghrs_wkend = ""
            hours = response.get("hours")
            if (hours is None):
                info = []
            else:
                operatinghrs_wkday = hours[0]['open'][1][
                    'start'] + "-" + hours[0]['open'][1]['end']
                operatinghrs_wkend = hours[0]['open'][0][
                    'start'] + "-" + hours[0]['open'][0]['end']
                #for times in hours[0]['open']:
                #    operatinghrs += day_map[times['day']] + ": " + times['start'] + "-" + times['end']
                info.append({
                    "text": "WkDay: " + operatinghrs_wkday,
                    "postback": ""
                })
                info.append({
                    "text": "WkEnd: " + operatinghrs_wkend,
                    "postback": ""
                })

            categories = response.get("categories")
            category_list = ", ".join(
                [category["title"] for category in categories])
            info.append({"text": "Cat: " + category_list, "postback": ""})

            info.append({
                "text": "Visit Yelp Page",
                "postback": response["url"]
            })

            info.append({
                "text":
                "Get Directions",
                "postback":
                "https://www.yelp.com/map/" + response["alias"]
            })

            reply = build_Card_Msg(response['name'], contact, url, info)
        else:
            reply = build_Singleline_Msg(response["error"]['description'])
    # return an error if there is an error getting the forecast
    except (ValueError, IOError) as error:
        return error

    return jsonify(reply)