diff --git a/tests/flask_stop.py b/tests/flask_stop.py index 1ed61ae..d3e3382 100644 --- a/tests/flask_stop.py +++ b/tests/flask_stop.py @@ -14,16 +14,4 @@ def run(): app.run() if __name__ == '__main__': - app.debug = True - print "starting process" - server = Process(target=run) - server.start() - - print "sleeping" - time.sleep(5) - - print "ending process" - server.terminate() - server.join() - - print "bye..." + app.run() \ No newline at end of file diff --git a/twiderboard/command.py b/twiderboard/command.py index 2694760..3a14350 100644 --- a/twiderboard/command.py +++ b/twiderboard/command.py @@ -9,7 +9,6 @@ import sys import data -from counter import Counter from streamer import HashtagLogger diff --git a/twiderboard/flask_app.py b/twiderboard/flask_app.py index e6073ed..ef09830 100644 --- a/twiderboard/flask_app.py +++ b/twiderboard/flask_app.py @@ -10,12 +10,6 @@ from datamodel import TrendyHashtag from datamodel import Tweet from datamodel import Member -from streamer import HashtagLogger - - -import signal -import sys - def connect(): """ @@ -64,24 +58,5 @@ def add_hashtag(): def index(): return render_template('statistics.html') - -class Twiderboard(): - def __init__(self): - # registering the signal to stop command line - signal.signal(signal.SIGINT, self.stop_handler) - - print "Starting streamer" - self.h = HashtagLogger(data.engine_url, oauth=data.oauth) - self.h.start() - - app.run() - - def stop_handler(self, signal, frame): - print "Stopping Streamer" - self.h.stop() - print "Stopping Command Line" - sys.exit(0) - - if __name__ == '__main__': - Twiderboard() + app.run() diff --git a/twiderboard/flask_stop.py b/twiderboard/flask_stop.py new file mode 100644 index 0000000..0ba42b3 --- /dev/null +++ b/twiderboard/flask_stop.py @@ -0,0 +1,40 @@ +from flask import Flask + +from streamer import HashtagLogger +import data +from flask import g + + +app = Flask(__name__) +h = HashtagLogger(data.engine_url, oauth=data.oauth) +h.start() + + +@app.route('/') +def index(): + return "Hi there!!!" + + +@app.route('/add_hashtag') +def add_hashtag(): + hashtag = h.add_hashtag('plop') + return hashtag + + +@app.route('/remove_hashtag') +def remove_hashtag(): + hashtag = h.remove_hashtag('plop') + return hashtag + + +@app.route('/stop') +def stop(): + h.stop() + return h.stream.engine + + +def run(): + app.run() + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/twiderboard/streamer.py b/twiderboard/streamer.py index 73d5601..1db8148 100644 --- a/twiderboard/streamer.py +++ b/twiderboard/streamer.py @@ -286,6 +286,8 @@ class HashtagLogger(): self.restart() engine.dispose() + return hashtag + def commit_hashtag(self, session): """ Takes care of errors that can happen if database if locked when session is commited @@ -325,6 +327,8 @@ class HashtagLogger(): self.restart() engine.dispose() + return hashtag + def connect(self): """ Separated so that the method can be run in each created thread.