Skip to content

Instantly share code, notes, and snippets.

@cmlsharp
Created March 2, 2019 18:12
Show Gist options
  • Save cmlsharp/d8ad700f3ff4e20d74f50b14291637ee to your computer and use it in GitHub Desktop.
Save cmlsharp/d8ad700f3ff4e20d74f50b14291637ee to your computer and use it in GitHub Desktop.
style50 demo
import os
import sys
from flask import Flask, redirect, render_template, request, url_for
import helpers
from analyzer import Analyzer
app = Flask(__name__)
@app.route( "/" )
def index():
return render_template( "index.html" )
@app.route("/search")
def search():
screen_name = request.args.get( "screen_name" , "" )
if not screen_name:
return redirect( url_for( "index" ))
tweets = helpers.get_user_timeline( screen_name , 100 )
if not tweets:
return redirect(url_for("index"))
positives = os.path.join(sys.path[ 0 ], "positive-words.txt")
negatives = os.path.join(sys.path[ 0 ] , "negative-words.txt")
analyzer = Analyzer(positives ,negatives )
positive, negative, neutral = 0, 0, 0
for tweet in tweets:
score = analyzer.analyze(tweet)
if score>0.0:
positive+=1
elif score < 0.0:
negative+=1
else:
neutral+=1
return render_template("search.html", chart=helpers.chart(positive, negative, neutral), screen_name=screen_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment