Ejemplo n.º 1
0
def get_news_united_arab_emirates():
    if "username" not in session:
        flash("Please Log In or Sign Up to register", "danger")
        return redirect("/login")

    news = get_news("ae")
    return render_template("region_news/united_arab_emirates_news.html", news=news)
Ejemplo n.º 2
0
def get_news_sweden():
    if "username" not in session:
        flash("Please Log In or Sign Up to register", "danger")
        return redirect("/login")

    news = get_news("se")
    return render_template("region_news/sweden_news.html", news=news)
Ejemplo n.º 3
0
def index():
    #product.py
    items = products.all()
    itemsupper = products.upper()
    itemslower = products.lower()

    #apis.py
    city = '東京都品川区平塚'
    if request.method == 'POST':
        city = request.form['keyword']
    lat, lng = apis.address_to_latlng(city)
    forecast = apis.get_weather(lat, lng)

    #nwesapi.py
    newsdict = newsapi.get_news("jp")
    topnews = newsapi.get_headline("jp")

    #foursquare.py
    spot = foursquare.get_name()

    return render_template('index.html',
                           city=city,
                           lat=lat,
                           lng=lng,
                           forecast=forecast,
                           items=items,
                           itemsupper=itemsupper,
                           itemslower=itemslower,
                           topnews=topnews,
                           newsdict=newsdict,
                           spot=spot)
Ejemplo n.º 4
0
def get_score():   
    title = ((get_target_title(sys.argv[1], 2))[0] + ".").lower()
    comprehend_client = init(sys.argv[2], sys.argv[3])
    keyphrases = get_key_phrases(comprehend_client, title)
    newsapi_keys = []
    for phrase in keyphrases:
        newsapi_keys.append(phrase["Text"])
    trust = get_news(" ".join(newsapi_keys))

    ## not enough reliable news to compare
    if len(trust) < 3:
        print(-1)
        return -1

    score = 0 
    for trustnews in trust:
        score = score + get_analyzer_mark(comprehend_client, title, trustnews)
    score = round((score/len(trust)), 1)
    print(score)
    return score
Ejemplo n.º 5
0
from newsapi import get_news
from datetime import datetime
from country_choices import short_codes as cc
from language_choices import short_codes as lc


def parametrize():
    parameters = dict()
    parameters['mode'] = input("Query type (top/everything): ")
    parameters['q'] = input("Query: ")
    if parameters['mode'] == 'everything':
        parameters['date_from'] = input("Date from (YYYY-MM-DD): ")
        parameters['date_to'] = input("Date to (YYYY-MM-DD): ")
        parameters['languages'] = input("Languages: ").split(', ')
        if parameters['languages'] == ['all']:
            parameters['languages'] = lc
    elif parameters['mode'] == 'top':
        parameters['countries'] = input("Countries: ").split(', ')
        if parameters['countries'] == ['all']:
            parameters['countries'] = cc
    else:
        raise Exception('No such query type!')
    return parameters


if __name__ == '__main__':
    parameters = parametrize()
    news = get_news(**parameters)
    db_name = datetime.today().strftime('db-%d-%m-%Y_%H-%M')
    save_all(news, db_name)