-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.py
More file actions
79 lines (63 loc) · 2.01 KB
/
bootstrap.py
File metadata and controls
79 lines (63 loc) · 2.01 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
#!/usr/bin/env python3
"""
bootstrap.py — CongressWatch repo health check and directory setup.
Creates required data directories, checks data state, prints summary.
"""
import os
import json
import sys
REQUIRED_DIRS = [
"data",
"data/details",
"data/bills",
"data/cache",
]
MEMBERS_FILE = "data/members.json"
BILLS_CACHE = "data/bills/all_bills.json"
DETAILS_DIR = "data/details"
def main():
print("CongressWatch — Bootstrap")
print("=" * 40)
# 1. Create required directories
for d in REQUIRED_DIRS:
if not os.path.exists(d):
os.makedirs(d, exist_ok=True)
print(f" Created: {d}/")
else:
print(f" OK: {d}/")
# 2. Check members.json
if not os.path.exists(MEMBERS_FILE):
print(f"\n [!] {MEMBERS_FILE} not found.")
print(" Run the fetch pipeline first:")
print(" python fetch.py")
print(" Or trigger the 'Fetch Congress Data' GitHub Action.")
sys.exit(1)
try:
with open(MEMBERS_FILE, "r") as f:
members = json.load(f)
member_count = len(members)
except Exception as e:
print(f"\n [!] Could not read {MEMBERS_FILE}: {e}")
sys.exit(1)
# 3. Count detail files
detail_count = 0
if os.path.exists(DETAILS_DIR):
detail_count = len([
f for f in os.listdir(DETAILS_DIR)
if f.endswith(".json")
])
# 4. Bills cache size
bills_size = "not found"
if os.path.exists(BILLS_CACHE):
size_bytes = os.path.getsize(BILLS_CACHE)
bills_size = f"{size_bytes / 1024 / 1024:.1f} MB"
# 5. Print summary
print(f"\n Data Summary:")
print(f" Members: {member_count}")
print(f" Detail files: {detail_count}")
print(f" Bills cache: {bills_size}")
scored = sum(1 for m in members if (m.get("score") or 0) > 0)
print(f" Members scored: {scored} / {member_count}")
print("\n Bootstrap complete.")
if __name__ == "__main__":
main()