I am trying to create a variable that I can retrieve outside of the function counts every time a chalice webhook alert is triggered. I cannot figure out how to get the variable out of the function. Here is my code. Thank you!
from chalice import Chalice
app = Chalice(app_name='tv_alert')
counter = None
@app.route('/')
def index():
return {'hello': 'world'}
@app.route('/tv', methods=['POST'])
def tv():
request = app.current_request
webhook_message = request.json_body
if webhook_message != 0:
counter += 1
return {
'message': 'I received the webhook notification!',
'webhook_message': webhook_message
}
print(counter)