Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 4,616 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 | # LocalView Scraper Scripts
Scripts for downloading and updating municipal meeting videos and transcripts from LocalView sources.
## Overview
LocalView tracks municipal government meetings across the U.S. This directory contains scrapers to:
- Download meeting videos from YouTube channels
- Extract transcripts and captions
- Update the dataset with 2025/2026 meetings
- Keep data current with ongoing meetings
## Data Sources
1. **Historical Data** (2006-2024): Harvard Dataverse
- URL: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/NJTBEM
- Download CSV files manually and place in `data/cache/localview/`
2. **Current Data** (2025+): YouTube scraper
- Scrape specific municipal YouTube channels
- Extract captions/transcripts automatically
- Update weekly/monthly
## Scripts
### `download_dataverse_dataset.py` - Download Historical Data
Downloads the LocalView dataset from Harvard Dataverse (requires manual auth).
```bash
# Interactive download with browser authentication
python scripts/localview/download_dataverse_dataset.py
```
### `scrape_youtube_channels.py` - Scrape Current Meetings
Scrapes municipal YouTube channels for new meeting videos.
```bash
# Scrape all known channels
python scripts/localview/scrape_youtube_channels.py --update
# Scrape specific channels
python scripts/localview/scrape_youtube_channels.py --channels "UCxxxxx,UCyyyyy"
# Scrape by state
python scripts/localview/scrape_youtube_channels.py --states CA,MA,TX
```
**Features:**
- Uses YouTube Data API v3
- Downloads video metadata
- Extracts captions/transcripts
- Detects meeting type (council, planning, etc.)
- Stores in LocalView format
### `extract_transcripts.py` - Download Captions
Extracts transcripts from YouTube videos using captions.
```bash
# Extract from all videos in cache
python scripts/localview/extract_transcripts.py
# Extract from specific videos
python scripts/localview/extract_transcripts.py --video-ids "abc123,def456"
```
### `update_municipality_list.py` - Update Channel List
Updates the list of municipal YouTube channels by searching for city government channels.
```bash
# Search for new municipal channels
python scripts/localview/update_municipality_list.py --states AL,GA,IN,MA,WA,WI
```
## Setup
### 1. Install Dependencies
```bash
pip install youtube-transcript-api google-api-python-client
```
### 2. Get YouTube API Key
1. Go to: https://console.cloud.google.com/apis/credentials
2. Create a new API key
3. Enable YouTube Data API v3
4. Add to `.env`:
```bash
YOUTUBE_API_KEY=your_api_key_here
```
### 3. Download Historical Data
Visit the Harvard Dataverse and download CSV files:
- https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/NJTBEM
Save to: `data/cache/localview/`
## Output Format
All scrapers output to the LocalView standard format:
**Municipalities** (`data/cache/localview/municipalities.csv`):
```csv
municipality_name,state,county,population,website_url,youtube_channel_id
```
**Videos** (`data/cache/localview/videos_{year}.csv`):
```csv
video_id,municipality_name,meeting_date,meeting_type,video_url,platform,duration_minutes,has_captions,transcript_available
```
**Transcripts** (`data/cache/localview/transcripts/{video_id}.txt`):
- Plain text transcripts
- One file per video
- Timestamps preserved in separate JSON
## Automation
### Weekly Update Cron Job
```bash
# Add to crontab for weekly updates
0 2 * * 0 cd /home/developer/projects/open-navigator && source .venv/bin/activate && python scripts/localview/scrape_youtube_channels.py --update
```
### Manual Update
```bash
# Update all data sources
./scripts/localview/update_all.sh
```
## Integration
After scraping, load data into Open Navigator:
```bash
# Load into bronze/gold tables
python pipeline/create_events_gold_tables.py
```
## Municipality Channels
Common patterns for finding municipal YouTube channels:
- Search: "[City Name] [State] government meetings"
- URL patterns:
- youtube.com/@[cityname]gov
- youtube.com/c/[CityName]Government
- youtube.com/user/[cityname]tv
## Troubleshooting
**API Quota Exceeded:**
- YouTube API has daily quota limits
- Use `--delay` flag to slow down requests
- Consider multiple API keys for high volume
**Missing Captions:**
- Not all videos have captions enabled
- Some municipalities use third-party platforms (Granicus, Archive.org)
- Check `has_captions` field before attempting extraction
**Authentication Issues:**
- Dataverse requires JavaScript/cookies
- Download manually in browser
- Cannot automate without institutional access
|