Ejemplo n.º 1
0
def result_page():
    url = request.args.get('url')
    post, zipcode, post_id = read_url(url)
    score = flag_score(url)
    words = get_bag_words()
    response = client.search.search(params={'source': 'CRAIG',
                                            'retvals': ','.join(RETVALS),
                                            'sort': 'timestamp',
                                            'external_id': post_id
                                            })
    with db:
        cur = db.cursor()
        if 'postings' not in response or response['postings'] == []:
            cur.execute(select_query_zip, zipcode)
        else:
            api_response = parse_post(response, DICT_FIELDS, LOC_FIELDS)
            cur.execute(select_query_full.format(api_response[0]['zipcode'],
                                                 api_response[0]['category'],
                                                 api_response[0]['category_group']))

        query_results = cur.fetchall()

    flag_results = []
    for result in query_results:
        flg_score = flag_score_post(result[2])
        flag_results.append(dict(heading=result[0], flagged_status=result[1],
                                 body=result[2], url=result[3],
                                 flag_score=flg_score))

    flag_results_sorted = sorted(flag_results, key=lambda k: k['flag_score'])
    return render_template('result.html', flag_results=flag_results_sorted, post=post,
                           score=str(score), WORDS=words)
Ejemplo n.º 2
0
def result_page():
    url = request.args.get("url")
    post, zipcode, post_id = read_url(url)
    score = flag_score(url)
    words = get_bag_words()
    response = client.search.search(
        params={"source": "CRAIG", "retvals": ",".join(RETVALS), "sort": "timestamp", "external_id": post_id}
    )
    with db:
        cur = db.cursor()
        if "postings" not in response or response["postings"] == []:
            cur.execute(select_query_zip, zipcode)
        else:
            api_response = parse_post(response, DICT_FIELDS, LOC_FIELDS)
            cur.execute(
                select_query_full.format(
                    api_response[0]["zipcode"], api_response[0]["category"], api_response[0]["category_group"]
                )
            )

        query_results = cur.fetchall()

    flag_results = []
    for result in query_results:
        flg_score = flag_score_post(result[2])
        flag_results.append(
            dict(heading=result[0], flagged_status=result[1], body=result[2], url=result[3], flag_score=flg_score)
        )

    flag_results_sorted = sorted(flag_results, key=lambda k: k["flag_score"])
    return render_template("result.html", flag_results=flag_results_sorted, post=post, score=str(score), WORDS=words)
Ejemplo n.º 3
0
def result_page():
    url = request.args.get('url')
    post, zipcode, post_id = read_url(url)
    score = flag_score(url)
    words = get_bag_words()
    response = client.search.search(
        params={
            'source': 'CRAIG',
            'retvals': ','.join(RETVALS),
            'sort': 'timestamp',
            'external_id': post_id
        })
    with db:
        cur = db.cursor()
        if 'postings' not in response or response['postings'] == []:
            cur.execute(select_query_zip, zipcode)
        else:
            api_response = parse_post(response, DICT_FIELDS, LOC_FIELDS)
            cur.execute(
                select_query_full.format(api_response[0]['zipcode'],
                                         api_response[0]['category'],
                                         api_response[0]['category_group']))

        query_results = cur.fetchall()

    flag_results = []
    for result in query_results:
        flg_score = flag_score_post(result[2])
        flag_results.append(
            dict(heading=result[0],
                 flagged_status=result[1],
                 body=result[2],
                 url=result[3],
                 flag_score=flg_score))

    flag_results_sorted = sorted(flag_results, key=lambda k: k['flag_score'])
    return render_template('result.html',
                           flag_results=flag_results_sorted,
                           post=post,
                           score=str(score),
                           WORDS=words)
Ejemplo n.º 4
0
def result_page():
    url = request.args.get('url')
    post, zipcode, post_id = read_url(url)
    score = flag_score(url)
    words = get_bag_words()
    response = client.search.search(params={'source': 'CRAIG',
                                            'retvals': ','.join(RETVALS),
                                            'sort': 'timestamp',
                                            'external_id': post_id
                                            })
    api_response = parse_post(response, DICT_FIELDS, LOC_FIELDS)
    if 'postings' not in response or response['postings'] == []:
        query_results = client.search.search(params={'source': 'CRAIG',
                                        'retvals': ','.join(RETVALS),
                                        'sort': 'timestamp',
                                        'location.zipcode': zipcode,
                                        'rpp': 100,
                                                     })
    else:
        price_range = str(api_response[0]['price'] - 500) + '..' + \
                  str(api_response[0]['price'] + 500)
        query_results = client.search.search(params={'source': 'CRAIG',
                                        'retvals': ','.join(RETVALS),
                                        'sort': 'timestamp',
                                        'category': api_response[0]['category'],
                                        'location.zipcode': api_response[0]['zipcode'],
                                        'category_group': api_response[0]['category_group'],
                                        'price': price_range,
                                        'rpp': 100,
                                        })

    flag_results = [dict(heading=result['heading'],
                                     body=result['body'], url=result['external_url'],
                                     flag_score=flag_score_post(result['body']))
                    for result in query_results['postings']]

    flag_results_sorted = sorted(flag_results, key=lambda k: k['flag_score'])
    return render_template('result.html', flag_results=flag_results_sorted, post=post,
                           score=str(score), WORDS=words)