Skip to content

Commit 73c0b3e

Browse files
committed
render decoding results as table
1 parent 30b1616 commit 73c0b3e

File tree

5 files changed

+87
-6
lines changed

5 files changed

+87
-6
lines changed

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def index():
99
if request.method == 'POST':
1010
qr = request.form['qr']
1111
json = decode(qr)
12-
return render_template('json.html', json=json)
12+
return render_template('json.html', cert=json)
1313
else:
1414
return render_template('form.html')
1515

decoder/decoder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ def decode(cert):
1313
cbor_data = cbor2.loads(cbor_data)
1414
json_data = cbor2.loads(cbor_data.value[2])
1515
json_data = json.dumps(json_data, indent=2)
16-
# object = json.loads(json_data)
17-
return json_data
16+
object = json.loads(json_data)
17+
object = object['-260']['1']
18+
return object

templates/form.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
{% extends "base.html" %}
22

3+
{% block title %}
4+
Decode your EU Digital COVID Certificate
5+
{% endblock %}
6+
37
{% block content %}
48
<form method="post">
5-
<textarea name="qr" rows="6" placeholder="HC1: …" required class="form-control mb-3"></textarea>
9+
<div class="form-group mb-3">
10+
<label>QR-Code Text</label>
11+
12+
<textarea name="qr" rows="10" placeholder="HC1: …" autofocus required minlength="100" maxlength="1000"
13+
class="form-control">HC1:6BF+70790T9WJWG.FKY*4GO0.O1CV2 O5 N2FBBRW1*70HS8WY04AC*WIFN0AHCD8KD97TK0F90KECTHGWJC0FDC:5AIA%G7X+AQB9746HS80:54IBQF60R6$A80X6S1BTYACG6M+9XG8KIAWNA91AY%67092L4WJCT3EHS8XJC$+DXJCCWENF6OF63W5NW6WF6%JC QE/IAYJC5LEW34U3ET7DXC9 QE-ED8%E.JCBECB1A-:8$96646AL60A60S6Q$D.UDRYA 96NF6L/5QW6307KQEPD09WEQDD+Q6TW6FA7C466KCN9E%961A6DL6FA7D46JPCT3E5JDLA7$Q6E464W5TG6..DX%DZJC6/DTZ9 QE5$CB$DA/D JC1/D3Z8WED1ECW.CCWE.Y92OAGY8MY9L+9MPCG/D5 C5IA5N9$PC5$CUZCY$5Y$527B+A4KZNQG5TKOWWD9FL%I8U$F7O2IBM85CWOC%LEZU4R/BXHDAHN 11$CA5MRI:AONFN7091K9FKIGIY%VWSSSU9%01FO2*FTPQ3C3F</textarea>
14+
15+
<small class="form-text text-muted">
16+
Get your QR-Code plain contents by reading it via a reader like <a href="https://zxing.org/w/decode.jspx" target="_blank">zxing.org</a> and paste the text above
17+
</small>
18+
</div>
19+
620
<input type="submit" value="decode" class="btn btn-primary w-100">
721
</form>
822
{% endblock %}

templates/includes/nav.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<nav class="navbar navbar-dark bg-dark mb-5">
22
<div class="container">
3-
<a class="navbar-brand" href="/">EU Digital COVID Certificate Converter</a>
3+
<a class="navbar-brand" href="/">
4+
EU Digital COVID Certificate Converter
5+
</a>
46
</div>
57
</nav>

templates/json.html

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,69 @@
11
{% extends "base.html" %}
22

3+
{% block title %}
4+
Your decoded EU Digital COVID Certificate
5+
{% endblock %}
6+
37
{% block content %}
4-
<pre><code>{{ json }}</code></pre>
8+
9+
<!-- <pre>
10+
<code>
11+
{{ cert }}
12+
</code>
13+
</pre> -->
14+
15+
16+
<table class="table">
17+
<thead>
18+
<tr>
19+
<th>key</th>
20+
<th>property</th>
21+
<th>value</th>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
<!-- level 1 -->
26+
{% for key in cert %}
27+
<tr>
28+
<td><code>{{ key }}</code></td>
29+
<td></td>
30+
<td>
31+
<!-- level 2 -->
32+
{% if cert[key] is mapping or cert[key] is not string %}
33+
<table class="table">
34+
<tbody>
35+
{% for key2 in cert[key] %}
36+
<tr>
37+
<td><code>{{ key2 }}</code></td>
38+
<td></td>
39+
<td>
40+
<!-- level 3 -->
41+
{% if cert[key][key2] is iterable and (cert[key][key2] is not string) %}
42+
<table class="table">
43+
<tbody>
44+
{% for key3 in cert[key][key2] %}
45+
<tr>
46+
<td><code>{{ key3 }}</code></td>
47+
<td></td>
48+
<td>{{ cert[key][key2][key3] }}</td>
49+
</tr>
50+
{% endfor %}
51+
</tbody>
52+
</table>
53+
{% else %}
54+
{{ cert[key][key2] }}
55+
{% endif %}
56+
</td>
57+
</tr>
58+
{% endfor %}
59+
</tbody>
60+
</table>
61+
{% else %}
62+
{{ cert[key] }}
63+
{% endif %}
64+
</td>
65+
</tr>
66+
{% endfor %}
67+
</tbody>
68+
</table>
569
{% endblock %}

0 commit comments

Comments
 (0)