Jobley / website · jobley.ai / tools / import-soc.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Regenerate the civilian occupation titles from saved official BLS 2018 major_groups.htm. |
| 3 | |
| 4 | Obtain the page from https://www.bls.gov/soc/2018/major_groups.htm (or blsmon1.bls.gov). |
| 5 | No data/license from elsewhere is copied; this imports public US federal classification facts. |
| 6 | """ |
| 7 | import json |
| 8 | import re |
| 9 | import sys |
| 10 | from html import unescape |
| 11 | from pathlib import Path |
| 12 | |
| 13 | html = Path(sys.argv[1]).read_text() |
| 14 | items = re.findall(r'<li>(\d\d-\d{4})(?:\s| )+<a\b[^>]*class="question"[^>]*>([^<]+)</a>', html) |
| 15 | assert len(items) == len({code for code, _ in items}) == 867 |
| 16 | civilian = [[code, unescape(title).strip()] for code, title in items if not code.startswith('55-')] |
| 17 | assert len(civilian) == 848 |
| 18 | out = Path(__file__).parent / 'career-titles.json' |
| 19 | out.write_text(json.dumps(civilian, ensure_ascii=False, separators=(',', ':')) + '\n') |