Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 73 lines (58 sloc) 2.74 KB
import numpy as np
import pandas as pd
#import datetime
#import pytz
from flask import Flask, make_response
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
@app.route('/flask', defaults={'path': ''})
def catch_all(path):
msg = '''
API example using Flask, numpy, pandas <br>
pointed at an -> <a href ="">HDF5</a> binary data store <br>
Nginx is pointed at a vanilla Flask server for this, Gunicorn for the rest of the site<br><br>
this is driven by this <a href="">code</a> <br><br>
please enter the api request like:<br>
{flask server}/api/v1.0/temp/begin_utc/end_utc/format<br>
begin_utc / end_utc are unix timestamps (int)<br>
format is either csv or json (string)<br>
e.g. <a href=""></a><br>
or <a href=""></a>'''
return msg + '<br>You entered: %s' % path
@app.route('/flask/api/v1.0/temp/<int:begin_utc>/<int:end_utc>/<format>', methods = ['GET'])
def get_temps(begin_utc, end_utc, format):
#begin_utc = datetime.datetime(begin_utc, pytz.UTC)
#end_utc = datetime.datetime(end_utc, pytz.UTC)
store = pd.HDFStore('/home/super_jgreenleaf/undst/data.h5')
df = store["df"]
r = df[(df['timeStamp']>=begin_utc) & (df['timeStamp']<=end_utc)]
if format == 'csv':
return r.to_csv(index=False, header=False, columns= ["temp", "timeStamp"])
return r.to_json(orient="records")
#format = "%Y-%m-%d %H:%M:%S.%f"
#return datetime.datetime.strptime(begin_utc, format)
#return datetime.datetime(begin_utc, pytz.UTC)
return 'blah'
app.wsgi_app = ProxyFix(app.wsgi_app)
if __name__ == '__main__':
#app.debug = True
# if not app.debug:
# import logging
# from logging.handlers import RotatingFileHandler
# file_handler = RotatingFileHandler('/tmp/hhh.log', 'a', 1 * 1024 * 1024, 10)
# file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
# app.logger.setLevel(logging.DEBUG)
# file_handler.setLevel(logging.DEBUG)
# app.logger.addHandler(file_handler)
#'hhh startup')
#if __name__ == '__main__':
#app.debug = True