aboutsummaryrefslogtreecommitdiff
path: root/extract-circuits
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-07-21 15:02:48 +0100
committerdiogo464 <[email protected]>2025-07-21 15:02:48 +0100
commit8c8dabd0ed20679a2dad43a5c239f9fcfe1c1ad7 (patch)
tree55abbcfbbff19efa3aaf6cf36540ac7651c54973 /extract-circuits
init
Diffstat (limited to 'extract-circuits')
-rwxr-xr-xextract-circuits85
1 files changed, 85 insertions, 0 deletions
diff --git a/extract-circuits b/extract-circuits
new file mode 100755
index 000000000..e7b9a5564
--- /dev/null
+++ b/extract-circuits
@@ -0,0 +1,85 @@
1#!/usr/bin/env python3
2import os
3import sys
4import json
5
6CIRCUIT_ATRP = "atrp"
7CIRCUIT_MAJORS = "majors"
8CIRCUIT_RIOS_TRAIL_TROPHY = "rios-trail-trophy"
9CIRCUIT_SUPER_HALFS = "super-halfs"
10CIRCUIT_ESTRELAS_DE_PORTUGAL = "estrelas-de-portugal"
11CIRCUIT_TROFEU_ATLETISMO_ALMADA = "trofeu-atletismo-almada"
12CIRCUIT_TROFEU_ALMADA = "trofeu-almada"
13CIRCUIT_ATLETISMO_BARREIRO = "atletismo-barreiro"
14CIRCUIT_MADEIRA_TRAIL = "circuit-madeira-trail"
15CIRCUITO_4_ESTACOES = "quatro-estacoes"
16
17CLASS_TO_CIRCUITS = {
18 "event_type_5-circuito-atrp": [CIRCUIT_ATRP],
19 "event_type_5-superhalfs": [CIRCUIT_SUPER_HALFS],
20 "event_type_5-trofeu-de-almada": [CIRCUIT_TROFEU_ALMADA],
21 "event_type_5-trofeu-atletismo-de-almada": [CIRCUIT_TROFEU_ATLETISMO_ALMADA],
22 "event_type_5-circuito-trail-madeira": [CIRCUIT_MADEIRA_TRAIL],
23 "event_type_5-circuito-estrelas-de-portugal": [CIRCUIT_ESTRELAS_DE_PORTUGAL],
24 "event_type_5-circuito-de-atletismo-do-barreiro": [CIRCUIT_ATLETISMO_BARREIRO],
25 "event_type_5-majors": [CIRCUIT_MAJORS],
26 "event_type_5-circuito-4-estacoes": [CIRCUIT_MAJORS],
27 "event_type_5-3-rios-trail-trophy": [CIRCUIT_RIOS_TRAIL_TROPHY],
28 "event_type_5-circuito-4-estacoes": [CIRCUITO_4_ESTACOES],
29 # ignored
30 "event_type-corrida-10km": [],
31 "event_type-corrida-10-km": [],
32 "event_type-corrida-de-15-km": [],
33 "event_type-meiamaratona": [],
34 "event_type-maratona": [],
35 "event_type-trail": [],
36 "event_type-kids-trail": [],
37 "event_type-trail-curto": [],
38 "event_type-trail-longo": [],
39 "event_type-trail-endurance": [],
40 "event_type-trail-ultra": [],
41 "event_type-sao-silvestre": [],
42 "event_type-outras": [],
43 "event_type-obstaculos": [],
44 "event_type-corta-mato": [],
45 "event_type-backyard-2": [],
46 "event_type-skyrunning": [],
47 "event_type-corridas-inferior-10": [],
48 "event_type-corrida": [],
49 "event_type-kids": [],
50 "event_type-caminhada": [],
51 "ajde_events": [],
52 "type-ajde_events": [],
53 "status-publish": [],
54 "has-post-thumbnail": [],
55 "hentry": [],
56}
57CLASS_IGNORE_PREFIXES = [
58 "post-",
59 "event_location-",
60 "event_organizer-",
61 "event_type_2-",
62 "event_type_4-",
63 "event_type_3-sim",
64]
65
66for slug in sys.argv[1:]:
67 data_path = os.path.join("events", slug, "data.json")
68 with open(data_path, "r") as f:
69 data = json.load(f)
70 classes = data["class_list"]
71 circuits = set()
72 circuits_path = os.path.join("events", slug, "circuits")
73 for class_ in classes:
74 if any(class_.startswith(p) for p in CLASS_IGNORE_PREFIXES):
75 continue
76 if class_ not in CLASS_TO_CIRCUITS:
77 raise Exception(f"unknown class: {class_}")
78 for category in CLASS_TO_CIRCUITS[class_]:
79 circuits.add(category)
80 with open(circuits_path, "w") as f:
81 for i, category in enumerate(sorted(circuits)):
82 if i > 0:
83 f.write("\n")
84 f.write(category)
85