Exemple #1
0
def yelp_search():
    search_term = request.form['term']
    location = request.form['location']

    data = {'term': search_term, 'location': location}
    query_string = urllib.urlencode(data)
    api_url = '%s?%s' % (app.config['YELP_SEARCH_URL'], query_string)
    signed_url = sign_url(api_url)
    response = requests.get(signed_url)
    json_response = json.loads(response.text)
    return render_template('results.html',
                           search_term=search_term,
                           location=location,
                           businesses=json_response['businesses'])
Exemple #2
0
def yelp_search():
    search_term = request.form['term']
    location = request.form['location']

    data = {
        'term': search_term,
        'location': location
    }
    query_string = urllib.urlencode(data)
    api_url = '%s?%s' % (app.config['YELP_SEARCH_URL'], query_string)
    signed_url = sign_url(api_url)
    response = requests.get(signed_url)
    json_response = json.loads(response.text)
    return render_template('results.html',
                            search_term=search_term,
                            location=location,
                            businesses=json_response['businesses'])
Exemple #3
0
def results():
    search_term = request.form['term']
    location = request.form['location']

    # will print search term in terminal
    # print "search: %s" % search_term


    # term and location are keys for the yelp api
    # they just happen to be the same as what we had
    # in the html file
    data = {
    'term': search_term,
    'location': location
    }

    query_string = urllib.urlencode(data) # encode this data

    # put the search terms in the url
    api_url = YELP_SEARCH_URL + "?" + query_string

    # authenticate the url with the yelp api
    signed_url = sign_url(api_url)

    # get the desired results from yelp
    # requests is a library
    # returns in the JSON format
    response = requests.get(signed_url)

    # get the fields from the json document:
    json_response = json.loads(response.text)

    return render_template('results.html',
                            search_term=search_term,
                            location=location,
                            businesses=json_response['businesses'])