forked from Open-EO/openeo-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (61 loc) · 2.21 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
from pprint import pprint
def declare_variables(variables, macro):
"""
This is the hook for the functions
- variables: the dictionary that contains the variables
- macro: a decorator function, to declare a macro.
"""
macro(build_error_list, 'error_codes')
def build_error_list():
with open('errors.json') as f:
data = json.load(f)
# Group by tag in a dict
errors = {}
tags = []
for key, val in data.items():
val['name'] = key
if 'description' not in val or val['description'] is None:
val['description'] = ""
if 'message' not in val or val['message'] is None:
raise Exception("No message specified for error: " + key)
if 'http' not in val or val['http'] is None:
raise Exception("No HTTP status code specified for error: " + key)
if 'tags' not in val or val['tags'] is None or not val['tags']:
raise Exception("No tags specified for error: " + key)
for tag in val['tags']:
if tag not in tags:
tags.append(tag)
errors[tag] = {}
errors[tag][key] = val
tags.sort()
# Create table of contents
html = ""
html += "<h3>Categories</h3>"
html += "<ul>"
for tag in tags:
html += "<li><a href='#" + slugify(tag) + "'>" + tag + "</a></li>"
html += "</ul>"
# Generate tables with errors
for tag in tags:
html += "<a name='" + slugify(tag) + "'></a>"
html += "<h3>" + tag + "</h3>"
html += "<table>"
html += "<tr>"
html += "<th>openEO Error Code</th>"
html += "<th>Description</th>"
html += "<th>Message</th>"
html += "<th>HTTP Status Code</th>"
html += "</tr>"
for key in sorted(errors[tag].keys()):
error = errors[tag][key]
html += "<tr>"
html += "<td>" + error['name'] + "</td>"
html += "<td>" + error['description'] + "</td>"
html += "<td>" + error['message'] + "</td>"
html += "<td>" + str(error['http']) + "</td>"
html += "</tr>"
html += "</table>"
return html
def slugify(title):
return title.lower().replace(' ', '_')