Exemple #1
0
def entertainment():
    news = lookup('entertainment')
    output = list()
    for ne in news:
        out = dict()
        sent = sentiment(ne['title'])
        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')
Exemple #2
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')
def do_tweet():
    tweet = request.forms.get('tweet')

    # clean tweet using predefined rules that are described in the Sentiment class
    clean_tweet = deepClean(cleanLine(tweet))

    # Check if tweet is in white list
    if clean_tweet in white_list:
        answer = white_list[clean_tweet]
    else:
        # Get an answer using the predefined classifier
        mySentiment = sentiment(classifier, clean_tweet)
        answer = {'pos': 'Positive', 'neg': 'Negative'}[mySentiment]
    return '''
        <html lang="en">
        <head>
        <meta charset="UTF-8">
        <title>Output</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
        </head>
        <body>
        <br><br><br><br><br><br><br><br><br><br><br><br><br><br>

        <div align="middle" style="width: 40%; margin: 0px auto;">
        <h3>Tweet: {tweet} <br> <br>
        <code>{answer}</code> </h3> <br>


        <form action="/thanks" method="post">
            <button name="bla" type="submit" class="btn btn-primary">Correct</button>
            <button name="incorrect" type="submit" class="btn btn-primary">Incorrect</button>

            <input name="answer" value="{answer}" type="hidden" />
            <input name="tweet" value="{tweet}" type = "hidden" />
            <input name="clean_tweet" value="{clean_tweet}" type = "hidden" />
        </form>

        </div>
        </body>
        </html>


        '''.format(tweet=tweet, answer=answer, clean_tweet=clean_tweet)