Ejemplo n.º 1
0
def main():
    tornado.options.define('port', default=8000, type=int, help="Listening Port")
    tornado.options.parse_command_line()

    # Connect to databases
    ercot_metadata = get_ercot_metadata()
    ercot_db = momoko.Pool(dsn='dbname=ercot', size=4)
    db_conn = psycopg2.connect(**get_pg_connect_kwargs('postgres:///ercot'))

    # Build handler kwargs
    ercot_kwargs = dict(metadata=ercot_metadata, db=ercot_db)

    # Configure application
    app = tornado.web.Application([
        (r'/pg/', ErcotPGResource, ercot_kwargs),
        (r'/py/', ErcotPyResource, ercot_kwargs),
        (r'/psy/', ErcotPsyResource, ercot_kwargs),
        (r'/array/', ErcotArrayResource, ercot_kwargs),
        (r'/array-sync/', ErcotArraySyncResource, dict(db=db_conn)),
    ], debug=True)

    # Start server
    server = tornado.httpserver.HTTPServer(app)
    server.bind(tornado.options.options.port)
    server.start(num_processes=1)
    tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 2
0

@app.route('/psy/')
@support_jsonp
def psy_resource():
    cursor = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    # cursor = conn.cursor(cursor_factory=extras.RealDictCursor)
    cursor.execute(sql)
    return app.response_class(
        json.dumps(list(cursor), default=dthandler),
        mimetype="application/json",
    )


# app.wsgi_app = Gzipper(app.wsgi_app)
conn = psycopg2.connect(**get_pg_connect_kwargs('postgres:///ercot'))

columns = (
    'timestamp',
    'actual_system_demand',
    'total_system_capacity',
)
# 2016 = 14 days / 10 minutes
sql = ("SELECT %s FROM ercot_realtime ORDER BY timestamp LIMIT 2016"
        % ', '.join(columns))

if __name__ == '__main__':
    port = 8000
    debug = True
    if len(sys.argv) == 2:
        try: