-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
57 lines (47 loc) · 1.57 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, render_template, request, jsonify
import requests
from dotenv import load_dotenv
import os
# Load environment variables from .env file
load_dotenv()
app = Flask(__name__)
# Retrieve the values from environment variables
TOKEN_ENDPOINT = os.getenv('TOKEN_ENDPOINT')
DATA_ENDPOINT = os.getenv('DATA_ENDPOINT')
CLIENT_ID = os.getenv('CLIENT_ID')
USERNAME = os.getenv('USER')
PASSWORD = os.getenv('PASSWORD')
@app.route('/')
def index():
return render_template('form.html')
@app.route('/data/<string:event_code>/<string:participant_id>', methods=['GET'])
def data(event_code, participant_id):
# Get the access token
token_response = requests.post(
TOKEN_ENDPOINT,
headers={
'Content-Type': 'application/x-www-form-urlencoded',
},
data={
'grant_type': 'password',
'username': USERNAME,
'password': PASSWORD,
'client_id': CLIENT_ID
}
)
token = token_response.json().get('access_token')
# Use the token to get the data
data_response = requests.get(
f"{DATA_ENDPOINT}?eventCode={event_code}&filter={{\"participantIdOrUuid\": \"{participant_id}\"}}",
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
}
)
data = data_response.json()
print("API Response:", data)
# Render the data in the HTML table
return render_template('table.html', data=data)
if __name__ == '__main__':
app.run(debug=True)