-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathprocess.py
More file actions
58 lines (43 loc) · 1.59 KB
/
process.py
File metadata and controls
58 lines (43 loc) · 1.59 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
"""
Process scraped HTML files into Markdown.
Reads from html/<slug>.html, writes to pages/<slug>.md.
Reuses parse_detail.parse_ooh_page() which is already tested.
Usage:
uv run python process.py # process all HTML files
uv run python process.py --force # re-process even if .md exists
"""
import argparse
import json
import os
from parse_detail import parse_ooh_page
def main():
parser = argparse.ArgumentParser(description="Convert HTML to Markdown")
parser.add_argument("--force", action="store_true", help="Re-process even if .md exists")
args = parser.parse_args()
os.makedirs("pages", exist_ok=True)
# Load master list for ordering/metadata
with open("occupations.json") as f:
occupations = json.load(f)
processed = 0
skipped = 0
missing = 0
for occ in occupations:
slug = occ["slug"]
html_path = f"html/{slug}.html"
md_path = f"pages/{slug}.md"
if not os.path.exists(html_path):
missing += 1
continue
if not args.force and os.path.exists(md_path):
skipped += 1
continue
md = parse_ooh_page(html_path)
with open(md_path, "w") as f:
f.write(md)
processed += 1
total_html = len([f for f in os.listdir("html") if f.endswith(".html")])
total_md = len([f for f in os.listdir("pages") if f.endswith(".md")])
print(f"Processed: {processed}, Skipped (cached): {skipped}, Missing HTML: {missing}")
print(f"Total: {total_html} HTML files, {total_md} Markdown files")
if __name__ == "__main__":
main()