コード例 #1
0
ファイル: app.py プロジェクト: m-ish/CompareTheBrew
def api_handler():
    term = request.args.get('term')
    order = request.args.get('order')
    print(term)
    print(order)

    # Get results the new way - by querying the database
    conn = db.create_connection()  # connect to the database
    tempResults = []
    # gather metrics info
    metrics(term)

    if order == "score_desc":
        tempResults = db.select_drink_by_smart_search(conn, term,
                                                      'DESC_efficiency')
    elif order == "score_asc":
        tempResults = db.select_drink_by_smart_search(conn, term,
                                                      'ASC_efficiency')
    elif order == "price_desc":
        tempResults = db.select_drink_by_smart_search(conn, term, 'DESC_price')
    elif order == "size_desc":
        tempResults = db.select_drink_by_smart_search(conn, term, 'DESC_ml')

    print(tempResults)

    data = {}

    # loop over tuples
    i = 0
    for result in tempResults:
        drink = dict()
        drink['id'] = result[0]
        drink['store'] = result[1]
        drink['brand'] = result[2]
        drink['name'] = result[3]
        drink['type'] = result[4]
        drink['price'] = result[5]
        drink['url'] = result[6]
        drink['volume'] = result[7]
        drink['percent'] = result[8]
        drink['drinks'] = result[9]
        drink['efficiency'] = result[10]
        drink['imglink'] = result[11]
        drink['img'] = result[12]
        data[i] = drink
        i = i + 1

    # return json_data
    return current_app.response_class(json.dumps(data),
                                      mimetype="application/json")
コード例 #2
0
ファイル: app.py プロジェクト: m-ish/CompareTheBrew
def display_top50spirits_page():
    # Get results the new way - by querying the database
    conn = db.create_connection()  # connect to the database
    tempResults = db.select_drink_by_smart_search(conn, "spirits",
                                                  'DESC_efficiency')
    # insert_ads_amongst_results(tempResults)

    # gather metrics info
    metrics(["spirits"])
    return render_template('top50.html', results=tempResults)
コード例 #3
0
ファイル: app.py プロジェクト: m-ish/CompareTheBrew
def display_worstscore_ResultPage(searchTerms):
    """
    Displays the search results page given the search terms

    Args:
        searchTerms: the searchTerms entered in the search (currently just the initial search terms entered)
    Returns:
        the rendered html template for the page
    """
    # Get results the new way - by querying the database
    conn = db.create_connection()  # connect to the database
    tempResults = db.select_drink_by_smart_search(conn, searchTerms,
                                                  'ASC_efficiency')
    # insert_ads_amongst_results(tempResults)

    # gather metrics info
    metrics(searchTerms)
    return render_template('results.html', results=tempResults)