File size: 7,212 Bytes
d15f07c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Scripts Directory

All scripts are organized into logical subdirectories by function.

## πŸ“‚ Directory Structure

```
scripts/
β”œβ”€β”€ data/                    # Data processing and migration
β”œβ”€β”€ datasources/             # Data source integrations and connectors
β”œβ”€β”€ deployment/              # Deployment and setup
β”œβ”€β”€ development/             # Development and debugging tools
β”œβ”€β”€ discovery/               # Jurisdiction discovery and URL finding
β”œβ”€β”€ enrichment/              # Data enrichment (990s, nonprofits)
β”œβ”€β”€ enrichment_ai/           # AI-powered analysis (Intel Arc optimized)
β”œβ”€β”€ huggingface/             # HuggingFace dataset management
β”œβ”€β”€ localview/               # LocalView YouTube scraper
β”œβ”€β”€ maintenance/             # Cleanup and maintenance
└── mcp/                     # Model Context Protocol server
```

## πŸ“– Folder Descriptions

### [data/](data/)
Data processing pipelines, migrations, and aggregations.
- Bill aggregations from PostgreSQL
- Gold table creation
- Contact extraction
- Data splits and partitioning

### [datasources/](datasources/)
Data source integrations and API connectors organized by external data source.

**Available Sources:**
- `openstates/` - OpenStates legislative data (bills, legislators, votes) - 8 scripts
  - βœ… **openstates_sources.py** - API integration for jurisdiction discovery
- `census/` - US Census Bureau geographic and demographic data - 3 scripts
- `irs/` - IRS nonprofit data (Form 990, Business Master File) - 5 scripts
  - βœ… **nonprofit_discovery.py** - Discover nonprofits by location/category
- `youtube/` - YouTube Data API integration - 1 script
  - βœ… **youtube_channel_discovery.py** - Discover municipal YouTube channels
- `social_media/` - Social media discovery (Facebook, Twitter, Instagram) - 1 script
  - βœ… **social_media_discovery.py** - Find social media accounts
- `fec/` - Federal Election Commission campaign finance data - 2 scripts
- `localview/` - LocalView meeting transcripts - 2 scripts
  - βœ… **dataverse_client.py** - Harvard Dataverse API client
- `google_data_commons/` - Google Data Commons demographic data - 1 script
- `gsa/` - GSA .gov domain registry - 1 script
- `ballotpedia/` - Ballotpedia election and official data - 1 script
- `google_civic/` - Google Civic Information API - 1 script
- `grants_gov/` - Grants.gov federal grant data - 1 script
- `meetingbank/` - MeetingBank research dataset - 1 script
- `nces/` - National Center for Education Statistics - 1 script
- `wikidata/` - Wikidata structured knowledge - 1 script
- `dbpedia/` - DBpedia structured Wikipedia data - 1 script
- `voter_data/` - Voter registration and turnout data - 1 script

See [datasources/README.md](datasources/README.md) for detailed documentation.

### [deployment/](deployment/)
Setup scripts for local development and production deployment.
- Local environment setup
- Database initialization
- Databricks deployment

### [development/](development/)
Development and debugging tools.
- Debug scripts for scrapers
- Testing utilities
- Development helpers

### [discovery/](discovery/)
Comprehensive jurisdiction discovery and data source identification.
- **Automated discovery** for all 90,000+ U.S. jurisdictions
- Official website URL finding
- YouTube channel discovery (with API integration)
- Meeting platform detection (Legistar, Granicus, SuiteOne)
- Social media account discovery
- Agenda portal identification
- Batch processing with quality metrics

**Key Scripts:**
- `discovery/archive/comprehensive_discovery_pipeline.py` - Master discovery for all jurisdictions (YouTube, platforms, social; legacy CLI)
- `discovery/comprehensive_discovery_pipeline_jurisdiction.py` - Meeting PDF / `scraped_meetings` crawl and optional contact extraction
- `youtube_channel_discovery.py` - Find municipal YouTube channels
- `platform_detector.py` - Detect meeting platforms
- `social_media_discovery.py` - Find social media accounts
- `batch_processor.py` - Process thousands of jurisdictions

See [discovery/README_NONPROFIT_DISCOVERY.md](discovery/README_NONPROFIT_DISCOVERY.md) for details.

### [enrichment/](enrichment/)
Scripts to enrich nonprofit data with additional metadata.
- 990 form downloads and processing
- Nonprofit profile enrichment
- Multiple data source integrations

### [enrichment_ai/](enrichment_ai/)
AI-powered legislative analysis using Intel Arc Graphics optimization.
- DuckDB + Vector Similarity Search
- Llama model inference (local)
- Intel IPEX and OpenVINO acceleration
- Bill and testimony analysis

See [enrichment_ai/README.md](enrichment_ai/README.md) for setup instructions.

### [huggingface/](huggingface/)
HuggingFace dataset preparation and upload.
- Dataset restructuring
- Multi-dataset uploads
- Finalization scripts

### [maintenance/](maintenance/)
System maintenance and cleanup utilities.
- Disk space cleanup
- File management
- Development utilities

## 🟫 Bronze Ingestion (`load_bronze.py`)

Runs all bronze-layer data loaders in sequence, then triggers dbt bronze models. Logs are written to `logs/load_bronze/<run_id>/`.

**Loaders (run in order):**
| Key | Source | Target Table(s) |
|---|---|---|
| `census` | Census Gazetteer | `bronze.bronze_jurisdictions_*` |
| `gsa` | GSA .gov Domains | `bronze.bronze_gov_domains` |
| `localview` | LocalView Meetings | `bronze.bronze_events_localview` |
| `irs` | IRS BMF Nonprofits | `bronze.bronze_organizations_nonprofits_irs` |

### Common usage

```bash
# Run all loaders + dbt bronze
python scripts/load_bronze.py

# Skip the dbt run at the end
python scripts/load_bronze.py --no-dbt

# Run only specific loaders
python scripts/load_bronze.py --only gsa census

# Skip specific loaders
python scripts/load_bronze.py --skip localview irs

# Clear supported tables before loading
python scripts/load_bronze.py --truncate

# Dry run β€” parse only, no DB writes (loaders that support it)
python scripts/load_bronze.py --dry-run
```

### Retrying failed steps

Each run saves a `results.json` in its log directory. Use `--retry-failed` to re-run only the steps that failed in the most recent run, or `--retry-run` to target a specific run by ID.

```bash
# Retry only failed steps from the most recent run
python scripts/load_bronze.py --retry-failed

# Retry only failed steps from a specific run
python scripts/load_bronze.py --retry-run 20260507_082303
```

To find recent run IDs:

```bash
ls logs/load_bronze/
```

The run ID is printed at the start of every run and in the summary. If the most recent run had no failures, `--retry-failed` exits immediately with a success message.

---

## πŸ” Finding Scripts

Use these commands to find scripts:

```bash
# List all scripts in a category
ls scripts/data/

# Search for a specific script
find scripts/ -name "*aggregate*"

# See what a script does
head -20 scripts/data/aggregate_bills_from_postgres.py
```

## ⚠️ Important Note

All scripts should be run from the project root directory:

```bash
# βœ… Correct
cd /home/developer/projects/open-navigator
python scripts/data/aggregate_bills_from_postgres.py

# ❌ Wrong
cd scripts/data
python aggregate_bills_from_postgres.py
```