-
-
Save qxf2/4e431b04a04e8c0b01a706dadddcf459 to your computer and use it in GitHub Desktop.
A gist to accompany the blog post about returning repeatable data patterns from a HTTP endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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