-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cgi
More file actions
executable file
·79 lines (66 loc) · 1.77 KB
/
list.cgi
File metadata and controls
executable file
·79 lines (66 loc) · 1.77 KB
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
73
74
75
76
77
78
#!/var/www/cgi/occupation-data/env/bin/python3
import csv
import os
import sys
from urllib.parse import parse_qs
import pandas
qs = parse_qs(os.environ["QUERY_STRING"])
LOCATION = qs.get('r', [""])[0]
CSVFILE = "TS060-2021-1.csv"
df = pandas.read_csv(CSVFILE)
df.set_index("Industry (current) (88 categories)", inplace=True)
if LOCATION == "ALL":
localdf = df.groupby(df.index).agg({"Observation": "sum", 'Industry (current) (88 categories) Code': "min"})
elif LOCATION in set(df["Lower Tier Local Authorities"]):
localdf = df[df["Lower Tier Local Authorities"] == LOCATION]
else:
print("Status:400")
print()
print(f"<{LOCATION}> is not in the list of locations.")
print("Select location with query string, e.g., /occupation-data/list.cgi?r=Sheffield")
print("Please see:")
print("https://geoportal.statistics.gov.uk/documents/d1fab2d9fb0a4576a7e08f89ac7e0b72/about")
print("Accepted locations follow:")
print()
for loc in sorted(set(df["Lower Tier Local Authorities"])):
print(loc)
sys.exit(1)
localdf = localdf.sort_values("Observation", ascending=False)
print("Content-type: text/html")
print()
print(f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
h1 {{
text-align: center;
}}
table td {{
max-width: 25rem;
}}
</style>
</head>
<body>
<h1>Occupation data for {LOCATION}</h1>
<a href="/occupation-data/">back to main page</a>
<table>
<tr>
<th>
Industry (current) (88 categories)
</th>
<th>
Observation (I think number of people), total={localdf["Observation"].sum():,}
</th>
</tr>
""")
for key, row in localdf.iterrows():
print("<tr>")
print(f'<td>{key}')
print(f'<td>{row["Observation"]:,}')
print("</tr>")
print("""
</table>
</body>
</html>
""")