-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdatedoc.py
More file actions
110 lines (83 loc) · 2.8 KB
/
updatedoc.py
File metadata and controls
110 lines (83 loc) · 2.8 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
import re
import subprocess
def executeDuckdbQuery(query, mode="markdown"):
command = f"duckdb db/wda.duckdb --{mode} '{query}'"
process = subprocess.run(
command,
shell=True,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
if process.returncode != 0:
print(
"###############################################################################"
)
print("# ERROR")
print(
"###############################################################################"
)
print("stderr:", process.stderr)
return process.stdout
def update_providers():
with open("README.md", "r", encoding="utf-8") as file:
content = file.read()
markdown = executeDuckdbQuery(
"SELECT * FROM wda_providers ORDER BY provider",
)
new_content = re.sub(
r"<!-- BEGIN PROVIDER -->.*<!-- END PROVIDER -->",
f"<!-- BEGIN PROVIDER -->\n\n{markdown}\n<!-- END PROVIDER -->",
content,
flags=re.DOTALL,
)
with open("README.md", "w", encoding="utf-8") as file:
file.write(new_content)
def update_scopesreference():
with open("README.md", "r", encoding="utf-8") as file:
content = file.read()
markdown = executeDuckdbQuery(
"SELECT * FROM wda_scopes_reference ORDER BY provider",
)
new_content = re.sub(
r"<!-- BEGIN SCOPEREFERENCE -->.*<!-- END SCOPEREFERENCE -->",
f"<!-- BEGIN SCOPEREFERENCE -->\n\n{markdown}\n<!-- END SCOPEREFERENCE -->",
content,
flags=re.DOTALL,
)
with open("README.md", "w", encoding="utf-8") as file:
file.write(new_content)
def update_datasets():
with open("README.md", "r", encoding="utf-8") as file:
content = file.read()
markdown = executeDuckdbQuery(
"SELECT * FROM wda_datasets ORDER BY provider",
)
new_content = re.sub(
r"<!-- BEGIN DATASET -->.*<!-- END DATASET -->",
f"<!-- BEGIN DATASET -->\n\n{markdown}\n<!-- END DATASET -->",
content,
flags=re.DOTALL,
)
with open("README.md", "w", encoding="utf-8") as file:
file.write(new_content)
def update_scopes():
with open("README.md", "r", encoding="utf-8") as file:
content = file.read()
markdown = executeDuckdbQuery(
"SELECT * FROM wda_scopes ORDER BY provider",
)
new_content = re.sub(
r"<!-- BEGIN SCOPE -->.*<!-- END SCOPE -->",
f"<!-- BEGIN SCOPE -->\n\n{markdown}\n<!-- END SCOPE -->",
content,
flags=re.DOTALL,
)
with open("README.md", "w", encoding="utf-8") as file:
file.write(new_content)
if __name__ == "__main__":
update_providers()
update_datasets()
update_scopesreference()