Esempio n. 1
0
#!/usr/bin/python

from flask import Flask, request, redirect, url_for, send_from_directory
import json, os, logging
import cfworker
import analysis

BUBBLE_STATS = analysis.bubblestats()
PIE_STATS = analysis.piestats()

#---------------------------------------------------------------
#
# app routes: end points for the app's web interfaces
#
#---------------------------------------------------------------
worker = cfworker.cfworker(port=int(os.getenv('PORT')))
worker.app = Flask(__name__, static_url_path='')


@worker.app.route('/')
def keen_chart():
    return worker.app.send_static_file('index.html')


@worker.app.route('/bubbles')
def bubble_chart():
    return worker.app.send_static_file('bubbles.html')


@worker.app.route('/sentiment')
def pie_chart():
    def on_success(self, data):
	message = json.dumps(data)
        channel.basic_publish(exchange='',routing_key=os.getenv('TASK_QUEUE'), body=message, 
		properties=pika.BasicProperties(
			delivery_mode = 2 #make message persist
		))
        print "[twitter-producer] Sent: %s" % data['text'].encode('utf-8')

    def on_error(self, status_code, data):
        print "[twitter-producer]: restarting after error: %s" % status_code
	time.sleep(30)
	python = sys.executable
	os.execl(python, python, * sys.argv)


worker = cfworker.cfworker( port=int(os.getenv('PORT')) )
worker.app = Flask(__name__)

@worker.app.route('/topic')
def topic():
	""" Allows other services to query the producer topic """
	return json.dumps({'topic':os.getenv('TOPIC')})

if __name__=='__main__':

	""" Leave this as is if deploying to CF, otherwise choose
	a port for local deployment (e.g. 8080) """

	worker.start()

	""" These variables can be set in your environment (ideal), or
Esempio n. 3
0
#!/usr/bin/python
import cfworker
import time, os

worker = cfworker.cfworker()
worker.start()

while True:
	print 'working...'
	time.sleep(2)

worker.stop()

#!/usr/bin/python
import cfworker
import time
import json

worker = cfworker.cfworker()
"""
Api Calls go here
"""


@worker.app.route('/<message>')
def hello(message):
    return json.dumps({'message': message})


"""
This is our asynchronous worker
"""
worker.start()
while True:
    time.sleep(3)
    print "Hello Python"

worker.stop()