Created
October 22, 2014 01:58
-
-
Save jasalt/16d8e04a77e13c05fb90 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from flask import Flask | |
| from secrets import g_user, g_pass | |
| from datetime import datetime | |
| app = Flask(__name__) | |
| import gspread | |
| # Helpers | |
| # B col is for date | |
| # D col is for drink type | |
| # Data starts from row 2 | |
| # Get empty row to which write into | |
| def empty_row(): | |
| row = 2 | |
| while (row < 100): | |
| if wks.acell('B' + str(row)).value is not "": | |
| row += 1 | |
| else: | |
| return row | |
| def current_time(): | |
| return datetime.now().isoformat() | |
| # Login with your Google account | |
| gc = gspread.login(g_user, g_pass) | |
| # Open a worksheet from spreadsheet with one shot | |
| wks = gc.open("coffee-watch-db").sheet1 | |
| # Api endpoints | |
| @app.route("/") | |
| def hello(): | |
| wks.update_acell('A1', "it's down there somewhere, let me take another look.") | |
| return "Hello World!" | |
| @app.route("/coffee") | |
| def drank_coffee(): | |
| row = empty_row() | |
| wks.update_acell('C' + str(row), "coffee") | |
| wks.update_acell('B' + str(row), current_time()) | |
| return ("Ok", 200) | |
| @app.route("/mate") | |
| def drank_mate(): | |
| row = empty_row() | |
| wks.update_acell('C' + str(row), "mate") | |
| wks.update_acell('B' + str(row), current_time()) | |
| return ("Ok", 200) | |
| if __name__ == "__main__": | |
| app.run(host='0.0.0.0', port=5000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment