Skip to content

Instantly share code, notes, and snippets.

@qxf2
Last active Aug 25, 2020
Embed
What would you like to do?
A gist to accompany the blog post about returning repeatable data patterns from a HTTP endpoint
"""
Mimick an endpoint that returns
- glucose levels of a patient
- as a time series
- since the last call made in the session
"""
from flask import Flask, session
app = Flask(__name__)
app.secret_key = b'DONT make your key public unless it is part of a throwaway example!'
with open('glucose_levels.csv','r') as fp:
GLUCOSE_DATA = fp.readlines()
@app.route('/glucose-level')
def glucose_levels():
"Return glucose levels"
session_count = session.get('count', 0)
line_number = session_count%len(GLUCOSE_DATA)
data = GLUCOSE_DATA[line_number]
session['count'] = session_count + 1
return data
#----START OF SCRIPT
if __name__=='__main__':
app.run('0.0.0.0',debug=True,port=6464)
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
97
98
99
100
199
200
200.01
199.99
105
104
103
102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment