Skip to content

Commit

Permalink
Add rq worker for heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie W committed Aug 11, 2017
1 parent 3a72e5e commit 9d8ea2c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import datetime
import pandas as pd
import dill
from rq import Queue
from worker import conn

app = Flask(__name__, static_url_path='')

Expand All @@ -31,6 +33,8 @@ def static_path(path):
def index():
if request.method =="GET":

q = Queue(connection=conn)

df = pd.read_csv('issue_comments_jupyter_copy.csv', sep=',')

df['org'] = df['org'].astype('str')
Expand Down Expand Up @@ -103,7 +107,7 @@ def index():
age = datetime.datetime.now() + datetime.timedelta(days=2)

if (age - datetime.datetime.now()).total_seconds() > 60*60*24:
happyface = happyfacer('issue_comments_jupyter_copy.csv')
happyface = q.enqueue(happyfacer('issue_comments_jupyter_copy.csv'))
dill.dump((datetime.datetime.now(), happyface), open('happyface.dill', 'wb'))
return render_template('index.html', script1=script1, div1=div1, happyface=happyface)

Expand Down
23 changes: 0 additions & 23 deletions happyfaces.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@

# coding: utf-8

# ### Sentiment Analysis

# # VADER: (Valence Aware Dictionary and sEntiment Reasoner)
#
# ### The best way to understand VADER is to look at the source code
# (Although it is a little unpolished) https://github.com/cjhutto/vaderSentiment
#
# Also see the actual dictionary at https://github.com/cjhutto/vaderSentiment/blob/master/vaderSentiment/vader_sentiment_lexicon.txt.
# You can install the code using `pip install vaderSentiment` but it might be better to download it so you can more easily modify it.
#
# ### VADER doesn't run in Python 3 because of line 23 in vaderSentiment.py
# See issue 11 for a fix: https://github.com/cjhutto/vaderSentiment/issues/11

# **Resources:**
# https://stackoverflow.com/questions/40325980/how-is-the-vader-compound-polarity-score-calculated-in-python-nltk

# You have to do this weird import in iPython notebook (Jupyter)
# because of the line "reload(sys)" in vaderSentiment.py
# See issue 7 for a simple fix: https://github.com/cjhutto/vaderSentiment/issues/7

import pandas as pd
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ oauthlib==0.7.2
requests>=2.2.1
simplejson==3.8.0
vadersentiment==2.5
rq==0.8.1
15 changes: 15 additions & 0 deletions worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

import redis
from rq import Worker, Queue, Connection

listen = ['high', 'default', 'low']

redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')

conn = redis.from_url(redis_url)

if __name__ == '__main__':
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()

0 comments on commit 9d8ea2c

Please sign in to comment.