Beispiel #1
0
def get_session():
    """
    Creates and disposes of a (scoped) session properly
    in a multithreaded application.
    From http://stackoverflow.com/q/5544774
    """
    session = Session()
    try:
        yield session
    except:
        session.rollback()
    finally:
        session.close()
Beispiel #2
0
def main():
    args = parse_args()
    if args['DEBUG']:
        from stream.process import Streamer
        from stream.util import join_threads
        streamer = Streamer()
        streamer.run(args['DEBUG'])
        try:
            join_threads(streamer.threads)
        except KeyboardInterrupt:
            print("\nKeyboardInterrupt caught.")
            print("Terminate main thread.")
            print("If only daemonic threads are left, terminate whole program.")
        finally:
            Session.remove()
    else:
        from stream.ui import app, MainWindow
        window = MainWindow()
        window.show()
        sys.exit(app.exec_())
Beispiel #3
0
def index():
    result = Session.execute("""
        select datetime((strftime('%s', created_at) / 900) * 900, 'unixepoch') interval,
        count(*) count
        from tweet
        group by interval
        order by interval;
    """)
    results = result.fetchall()
    d = {}
    for a, b in results:
        d[str(a)] = b
    json_results = json.dumps(d)
    return render_template('index.html', results=json_results)
Beispiel #4
0
def index():
    result = Session.execute("""
        select datetime((strftime('%s', created_at) / 900) * 900, 'unixepoch') interval,
        count(*) count
        from tweet
        group by interval
        order by interval;
    """)
    results = result.fetchall()
    d = {}
    for a, b in results:
        d[str(a)] = b
    json_results = json.dumps(d)
    return render_template('index.html', results=json_results)