A real-time California Highway Patrol traffic incident monitoring system using Server-Sent Events (SSE) for live updates. This is a streamlined, SSE-only implementation that eliminates file dependencies and provides instant real-time updates.
- Backend: Python scraper with built-in HTTP server and SSE streaming
- Frontend: JavaScript client that connects via SSE for real-time updates
- Data Flow: Scraper β HTTP Server β SSE Stream β Frontend (no file storage)
- Deployment: Railway with automatic scaling and zero configuration
- β‘ Real-time Updates: SSE streaming with sub-second latency
- π« No File Dependencies: Data flows directly from scraper to frontend
- π Railway Deployment: One-click deployment with automatic scaling
- π± Responsive UI: Modern, mobile-friendly interface
- π Auto-reconnection: Robust SSE connection handling
- π° Cost Effective: $5-15/month (vs $35-40/month for WebSocket alternatives)
/Users/jace/Desktop/nick traffic/
βββ src/ # Python Backend (SSE-only)
β βββ core/ # Core modules
β β βββ data_manager.py # Data management (SSE streaming)
β β βββ incident_parser.py # CHP data parsing
β β βββ center_mapper.py # Center code mapping
β β βββ ... # Other core modules
β βββ scrapers/
β βββ continuous_scraper.py # Main SSE scraper
βββ js/ # JavaScript Frontend (SSE-only)
β βββ app-railway.js # Main Railway app entry point
β βββ config/
β β βββ railway-dependency-config.js # SSE-only dependency injection
β βββ controllers/
β β βββ railway-app-controller.js # SSE-only app controller
β βββ services/
β β βββ sse-service.js # SSE connection handling
β β βββ incident-realtime-service.js # Real-time data processing
β β βββ incident-data-service.js # Data caching
β β βββ ... # Other SSE services
β βββ ... # UI components and utilities
βββ assets/ # Static assets
β βββ styles.css # CSS styles
β βββ chromedriver-mac-arm64/ # Chrome driver (local dev only)
βββ diagnostics_suite/ # Testing and diagnostics
βββ email_templates/ # Email notification templates
βββ docs/ # Documentation
βββ index.html # Main HTML file
βββ package.json # Node.js dependencies (minimal)
βββ requirements.txt # Python dependencies
βββ railway.toml # Railway deployment config
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose config
- Fork this repository
- Connect to Railway: Deploy to Railway
- Deploy: Railway automatically builds and deploys
- Access: Your live dashboard will be available at
https://your-app.railway.app
# Clone the repository
git clone https://github.com/your-username/chp-traffic-scraper.git
cd chp-traffic-scraper
# Install Python dependencies
pip install -r requirements.txt
# Install Node.js dependencies (minimal)
npm install
# Run the SSE scraper locally
python src/scrapers/continuous_scraper.py
# Open in browser
open http://localhost:8080
# Build and run with Docker
./docker-commands.sh build
./docker-commands.sh run
# Access the application
open http://localhost:8080
COMMUNICATION_CENTER
: Center to scrape (default: BCCC)ENABLE_EMAIL_NOTIFICATIONS
: Enable/disable emails (default: false)GMAIL_SENDER_EMAIL
: Sender email addressGMAIL_RECIPIENT_EMAIL
: Recipient email addressGMAIL_APP_PASSWORD
: Gmail App Password
The system supports all 25 CHP Communication Centers:
- BCCC: Border Communications Center
- LACC: Los Angeles Communications Center
- SACC: Sacramento Communications Center
- OCCC: Orange County Communications Center
- GGCC: Golden Gate Communications Center
- FRCC: Fresno Communications Center
- CHCC: Chico Communications Center
- HMCC: Humboldt Communications Center
- INCC: Inland Communications Center
- ICCC: Indio Communications Center
- MRCC: Merced Communications Center
- MYCC: Monterey Communications Center
- RDCC: Redding Communications Center
- SLCC: San Luis Obispo Communications Center
- SKCCSTCC: Stockton Communications Center
- SUCC: Susanville Communications Center
- TKCC: Truckee Communications Center
- UKCC: Ukiah Communications Center
- VTCC: Ventura Communications Center
- YKCC: Yreka Communications Center
- BFCC: Bakersfield Communications Center
- BSCC: Barstow Communications Center
- BICC: Bishop Communications Center
- CCCC: Capitol Communications Center
- ECCC: El Centro Communications Center
The Python scraper includes a built-in HTTP server with SSE streaming:
# SSE endpoint for real-time updates
@app.get('/api/incidents/stream')
async def stream_incidents(request):
async def event_generator():
while True:
# Scrape data every 5 seconds
incidents = await scrape_incidents()
# Stream to all connected clients
yield f"data: {json.dumps(incidents)}\n\n"
await asyncio.sleep(5)
return StreamingResponse(event_generator(), media_type='text/plain')
The JavaScript frontend connects via SSE for real-time updates:
// SSE connection for real-time updates
class SSEService {
connect() {
this.eventSource = new EventSource('/api/incidents/stream');
this.eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
this.handleIncidentUpdate(data);
};
}
}
- Scraper: Runs every 5 seconds, scrapes CHP website
- HTTP Server: Receives scraped data, streams via SSE
- SSE Stream: Real-time data stream to all connected clients
- Frontend: Receives updates, updates UI instantly
{
"type": "incident_update",
"center": "BCCC",
"data": {
"center_code": "BCCC",
"center_name": "Border",
"incident_count": 18,
"incidents": [
{
"id": "240928-001",
"time": "2025-09-28T14:30:00",
"location": "I-5 N at Border",
"description": "Traffic collision",
"severity": "Moderate"
}
],
"last_updated": "2025-09-28T17:45:19.641000"
}
}
incident_update
: Individual center updatesinitial_data
: Complete data on connectionscrape_summary
: Scraping results summarydelta_update
: New/removed incidents
- β‘ 5-second intervals: Scrapes CHP website every 5 seconds
- π Live updates: SSE streaming with sub-second latency
- π± Multi-center: All 25 CHP Communication Centers
- π Auto-reconnection: Robust connection handling
- π± Responsive design: Works on desktop, tablet, and mobile
- π¨ Dark/Light theme: Automatic theme switching
- π Real-time filtering: Filter by center, type, location
- π Copy to clipboard: Easy incident sharing
- π§ Instant alerts: New incident notifications
- π Resolved alerts: Incident resolution notifications
- βοΈ Configurable: Enable/disable via environment variables
- π Railway: One-click deployment with automatic scaling
- π³ Docker: Containerized deployment option
- π§ Zero config: Works out of the box
- No API keys: No external API dependencies
- Environment variables: All sensitive data in environment variables
- HTTPS: Automatic HTTPS on Railway
- CSP headers: Content Security Policy for XSS protection
- Backend: Add modules in
src/core/
orsrc/scrapers/
- Frontend: Add services in
js/services/
- UI: Add components in
js/
directory - Testing: Use
diagnostics_suite/
for testing
# Test SSE scraper locally
python src/scrapers/continuous_scraper.py
# Test with diagnostics
open diagnostics_suite/sse-diagnostics.py
# Test Docker deployment
./docker-commands.sh dev
- SSE Connection: Check browser Network tab for SSE stream
- Scraper: Check console logs for scraping status
- Data Flow: Use
diagnostics_suite/
tools
- SSE: Simpler, more reliable, better browser support
- WebSocket: More complex, requires connection management
- Choice: SSE chosen for simplicity and reliability
- Interval: 5 seconds (configurable)
- Centers: All 25 centers in parallel
- Latency: Sub-second from scrape to UI update
- Reliability: Auto-retry on failures
- Cost: $5-15/month
- Features: Automatic scaling, HTTPS, zero config
- Deployment: One-click from GitHub
- URL:
https://your-app.railway.app
- Local:
docker-compose up
- Production: Deploy to any Docker host
- Ports: 8080 (HTTP/SSE), 3000 (Frontend)
- Python:
python src/scrapers/continuous_scraper.py
- Frontend: Served by Python HTTP server
- URL:
http://localhost:8080
- β WebSocket β SSE: Simpler, more reliable
- β File storage β Direct streaming: No file dependencies
- β Multi-center β SSE-only: Streamlined architecture
- β Complex setup β Zero config: Railway deployment
- β Real-time updates: Still sub-second latency
- β All 25 centers: Full CHP coverage
- β Email notifications: Still supported
- β Responsive UI: Same modern interface
- Fork the repository
- Create a feature branch
- Make your changes
- Test with
diagnostics_suite/
- Submit a pull request
MIT License - see LICENSE file for details.
- CHP: California Highway Patrol for providing incident data
- Railway: For seamless deployment platform
- Community: For feedback and contributions
Live Demo: Deploy to Railway | Issues: GitHub Issues | Documentation: Full Docs