コード例 #1
0
ファイル: score_app.py プロジェクト: tspannhw/moves
# needed to make this application accessable for cross domain access
@app.after_request
def after_request(response):
  response.headers.add('Access-Control-Allow-Origin', '*')
  response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
  response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
  return response

@app.route('/score/<string:channel>')
def score(channel):
    model_store_key = 'channel_{}_model'.format(channel)
    cl = cPickle.loads(r[model_store_key])
    rkey = 'channel_{}_scoring'.format(channel)

    r.ltrim(rkey,0,100) # trim so this doesn't blow up
    data = r.lrange(rkey,0,win_size-1)
    return jsonify(**score_in_data(data, cl,channel))
    
if os.environ.get('VCAP_SERVICES') is None: # running locally
    PORT = 8082
    DEBUG = True
    redis_service_name = None
else:                                       # running on CF
    PORT = int(os.getenv("PORT"))
    DEBUG = False
    redis_service_name = 'p-redis'

r = helper_functions.connect_redis_db(redis_service_name)
app.run(host='0.0.0.0', port=PORT, debug=DEBUG,threaded=True)
コード例 #2
0
ファイル: app.py プロジェクト: tspannhw/twitter-nlp
import time

import redis
from flask import Flask, request, Response, render_template
from gevent import monkey, sleep, socket
from gevent.pywsgi import WSGIServer

import helper_functions

monkey.patch_all()

app = Flask(__name__)
redis.connection.socket = socket

# connect to redis for storing logging info
r = helper_functions.connect_redis_db()

# twitter compute and stats URL, from manifest
SENTIMENT_COMPUTE_URL = os.getenv('SENTIMENT_COMPUTE_URL', None)
SENTIMENT_STATS_URL = os.getenv('SENTIMENT_STATS_URL', None)


def gen_dashboard_tweets():
    n = 5  # min number of seconds between each tweet
    pubsub = r.pubsub()
    pubsub.subscribe('tweet_msgs')
    for message in pubsub.listen():
        is_a_tweet = message['type'] == 'message'
        is_tweet_message = message['channel'] == 'tweet_msgs'
        if not is_a_tweet or not is_tweet_message:
            continue
コード例 #3
0
def after_request(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
    return response


@app.route('/score/<string:channel>')
def score(channel):
    model_store_key = 'channel_{}_model'.format(channel)
    cl = cPickle.loads(r[model_store_key])
    rkey = 'channel_{}_scoring'.format(channel)

    r.ltrim(rkey, 0, 100)  # trim so this doesn't blow up
    data = r.lrange(rkey, 0, win_size - 1)
    return jsonify(**score_in_data(data, cl, channel))


if os.environ.get('VCAP_SERVICES') is None:  # running locally
    PORT = 8082
    DEBUG = True
    redis_service_name = None
else:  # running on CF
    PORT = int(os.getenv("PORT"))
    DEBUG = False
    redis_service_name = 'rediscloud'

r = helper_functions.connect_redis_db(redis_service_name)
app.run(host='0.0.0.0', port=PORT, debug=DEBUG, threaded=True)