-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_phrases.py
More file actions
42 lines (31 loc) · 1.2 KB
/
install_phrases.py
File metadata and controls
42 lines (31 loc) · 1.2 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
import re
with open('phrases_review.md', 'r') as f:
text = f.read()
tiers = [
"STORM", "RAIN SOON", "RAIN NOW", "SNOW", "HOT", "COLD", "WIND",
"HIGH UV", "BAD AIR", "MUGGY", "PLEASANT"
]
var_names = [
"PHRASES_STORM", "PHRASES_RAIN_SOON", "PHRASES_RAIN_NOW", "PHRASES_SNOW",
"PHRASES_HOT", "PHRASES_COLD", "PHRASES_WIND", "PHRASES_HIGH_UV",
"PHRASES_BAD_AIR", "PHRASES_MUGGY", "PHRASES_PLEASANT"
]
blocks = re.split(r'## \d+\. .*?\n', text)[1:]
replacements = {}
for i, block in enumerate(blocks):
lines = block.strip().split('\n')
phrases = []
for line in lines:
match = re.match(r'\d+\.\s+"(.*?)"', line)
if match:
phrases.append(f' "{match.group(1)}"')
var_name = var_names[i]
c_array = f'static const char *const {var_name}[] = {{\n' + ',\n'.join(phrases) + '\n};'
pattern = r'static const char \*const ' + var_name + r'\[\] = \{.*?\};'
replacements[pattern] = c_array
with open('update_phrases.py', 'r') as f:
update_script = f.read()
for pat, repl in replacements.items():
update_script = re.sub(pat, repl, update_script, flags=re.DOTALL)
with open('update_phrases.py', 'w') as f:
f.write(update_script)