Skip to content

Instantly share code, notes, and snippets.

@nebelgrau77
Last active April 4, 2020 06:31
Show Gist options
  • Save nebelgrau77/57e39ffa2f5b18b94d9dedc091264592 to your computer and use it in GitHub Desktop.
Save nebelgrau77/57e39ffa2f5b18b94d9dedc091264592 to your computer and use it in GitHub Desktop.
simple counter in flask
# this won't work, either:
# in flask_app:
from counter import counter_update, counter_display
@app.route('/counter/')
def counter():
counter = counter_display()
return render_template('counter.html', counter = counter)
@app.route('/counter/update/API_key=<api_key>/mac=<mac>/data=<data>', methods=['GET'])
def update_counter(api_key, mac, data):
if (api_key == API_KEY and mac == MAC_ADDRESS):
counter_update(data)
return 'update completed'
else:
return render_template('403.html')
# counter.py
counter = 0
def counter_update(new_counter):
counter = new_counter
return counter
def counter_display():
return counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment