Пример #1
0
def politics():
    news=lookup('politics')
    output=list()
    for ne in news:
        sent=sentiment(ne['title'])
        out=dict()
        out['title']=ne['title']
        out['description']=ne['description']
        out['url'] =ne['url']
        out['sentiment']=sent[0]['sentiment']
        output.append(out)
        """words=ne['title'].split()
        query=words[0]+" "+words[1]+" "+words[2]
        t_reviews=tweet(query)#t_reviews is a list of tweets
        out=dict()
        out['title']=ne['title']
        out['description']=ne['description']
        out['url']=ne['url']
        out['reviews']=list()
        for rev in t_reviews:
            sent=sentiment(rev)
            time.sleep(0.2)
            if sent[0]["sentiment"] != 0:
                sen=dict()
                sen['tweet']=rev
                sen['sentiment']=sent[0]['sentiment']
                out['reviews'].append(sen)
        output.append(out)"""
    return render_template('news.html',output=output,topic='politics')
Пример #2
0
def entertainment():
    news=lookup('entertainment')
    output=list()
    for ne in news:
        out=dict()
        out['title']=ne['title']
        out['description']=ne['description']
        out['url'] =ne['url']
        out['sentiment']=sent[0]['sentiment']
        output.append(out)
        """t_reviews=tweet(ne['title'])#t_reviews is a list of tweets
        out=dict()
        out['title']=ne['title']
        out['description']=ne['description']
        out['url']=ne['url']
        out['reviews']=list()
        for rev in t_reviews:
            sent=sentiment(rev)
            if sent[0]["sentiment"] != 0:
                sen=dict()
                sen['tweet']=rev
                sen['sentiment']=sent[0]['sentiment']
                out['reviews'].append(sen)
        output.append(out)"""
    return render_template('news.html',output=output,topic='entertainment')
Пример #3
0
from get_news import lookup
data = lookup("Sports")
print(type(data))
print(dir(data))
print(data)