HKIA Content Aggregation System - Complete content scraping and markdown generation for 5 sources (WordPress, MailChimp RSS, Podcast RSS, YouTube, Instagram)
MAJOR CHANGES: - TikTok scraper disabled in orchestrator (GUI dependency issues) - Created new hkia-scraper systemd services replacing hvac-content-* - Added comprehensive installation script: install-hkia-services.sh - Updated documentation to reflect 5 active sources (WordPress, MailChimp, Podcast, YouTube, Instagram) PRODUCTION DEPLOYMENT: - Services installed and active: hkia-scraper.timer, hkia-scraper-nas.timer - Schedule: 8:00 AM & 12:00 PM ADT scraping + 30min NAS sync - All sources now run in parallel (no TikTok GUI blocking) - Automated twice-daily content aggregation with image downloads TECHNICAL: - Orchestrator simplified: removed TikTok special handling - Service files: proper naming convention (hkia-scraper vs hvac-content) - Documentation: marked TikTok as disabled, updated deployment status 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| config | ||
| data_api_test | ||
| data_production_backlog | ||
| data_quick_test | ||
| deploy | ||
| docs | ||
| monitoring | ||
| src | ||
| systemd | ||
| test_data | ||
| test_fix | ||
| tests | ||
| .env.production | ||
| .gitignore | ||
| .python-version | ||
| automated_backlog_capture.py | ||
| BACKLOG_STATUS.md | ||
| capture_tiktok_backlog.py | ||
| claude.md | ||
| CLAUDE.md | ||
| clean_markdown.py | ||
| consolidate_current_files.py | ||
| continue_youtube_captions.py | ||
| create_instagram_incremental.py | ||
| debug_content.py | ||
| debug_wordpress.py | ||
| debug_wordpress_raw.py | ||
| debug_youtube_detailed.py | ||
| debug_youtube_videos.py | ||
| DEPLOY.md | ||
| deploy_production.sh | ||
| detailed_monitor.py | ||
| fetch_more_youtube.py | ||
| fetch_youtube_100_with_transcripts.py | ||
| fetch_youtube_with_transcripts.py | ||
| FINAL_TALLY_REPORT.md | ||
| final_verification.py | ||
| install-hkia-services.sh | ||
| install.sh | ||
| install_production.sh | ||
| main.py | ||
| monitor_backlog.py | ||
| monitor_backlog_progress.sh | ||
| production_backlog_capture.py | ||
| pyproject.toml | ||
| quick_backlog_test.py | ||
| README.md | ||
| requirements.txt | ||
| requirements_new.txt | ||
| resume_instagram_capture.py | ||
| run_api_production_v2.py | ||
| run_api_scrapers_production.py | ||
| run_instagram_next_1000.py | ||
| run_production.py | ||
| run_production_cumulative.py | ||
| run_production_with_images.py | ||
| status.md | ||
| test_api_scrapers_full.py | ||
| test_cumulative_fix.py | ||
| test_cumulative_mode.py | ||
| test_image_downloads.py | ||
| test_instagram_debug.py | ||
| test_instagram_fix.py | ||
| test_mailchimp_api.py | ||
| test_markitdown_fix.py | ||
| test_new_auth.py | ||
| test_production_deployment.py | ||
| test_real_data.py | ||
| test_slow_delays.py | ||
| test_sources_simple.py | ||
| test_tiktok_advanced.py | ||
| test_tiktok_scrapling.py | ||
| test_wordpress_clean.py | ||
| test_youtube_api.py | ||
| test_youtube_auth.py | ||
| test_youtube_scraper_enhanced.py | ||
| test_youtube_transcript.py | ||
| test_youtube_transcripts.py | ||
| update_docs_to_hkia.py | ||
| update_to_hkia_naming.py | ||
| UPDATED_CAPTURE_STATUS.md | ||
| uv.lock | ||
| validate_production.sh | ||
| verify_processing.py | ||
| youtube_auth.py | ||
| youtube_backlog_all_with_transcripts.py | ||
| youtube_backlog_with_transcripts_slow.py | ||
| youtube_browser_cookies.py | ||
| youtube_slow_backlog_with_transcripts.py | ||
HKIA Content Aggregation System
A containerized Python application that aggregates content from multiple HKIA sources, converts them to markdown format, and syncs to a NAS.
Features
- Multi-source content aggregation from YouTube, Instagram, TikTok, MailChimp, WordPress, and Podcast RSS
- Comprehensive image downloading for all visual content (Instagram posts, YouTube thumbnails, Podcast artwork)
- Cumulative markdown management - Single source-of-truth files that grow with backlog and incremental updates
- API integrations for YouTube Data API v3 and MailChimp API
- Intelligent content merging with caption/transcript updates and metric tracking
- Automated NAS synchronization to
/mnt/nas/hkia/for both markdown and media files - State management for incremental updates
- Parallel processing for multiple sources
- Atlantic timezone (America/Halifax) timestamps
Cumulative Markdown System
Overview
The system maintains a single markdown file per source that combines:
- Initial backlog content (historical data)
- Daily incremental updates (new content)
- Content updates (new captions, updated metrics)
How It Works
- Initial Backlog: First run creates base file with all historical content
- Daily Incremental: Subsequent runs merge new content into existing file
- Smart Merging: Updates existing entries when better data is available (captions, transcripts, metrics)
- Archival: Previous versions archived with timestamps for history
File Naming Convention
<brandName>_<source>_<dateTime>.md
Example: hkia_YouTube_2025-08-19T143045.md
Quick Start
Installation
# Install UV package manager
pip install uv
# Install dependencies
uv pip install -r requirements.txt
Configuration
Create .env file with credentials:
# YouTube
YOUTUBE_API_KEY=your_api_key
# MailChimp
MAILCHIMP_API_KEY=your_api_key
MAILCHIMP_SERVER_PREFIX=us10
# Instagram
INSTAGRAM_USERNAME=username
INSTAGRAM_PASSWORD=password
# WordPress
WORDPRESS_USERNAME=username
WORDPRESS_API_KEY=api_key
Running
# Run all scrapers (parallel)
uv run python run_all_scrapers.py
# Run single source
uv run python -m src.youtube_api_scraper_v2
# Test cumulative mode
uv run python test_cumulative_mode.py
# Consolidate existing files
uv run python consolidate_current_files.py
Architecture
Core Components
- BaseScraper: Abstract base class for all scrapers
- BaseScraperCumulative: Enhanced base with cumulative support
- CumulativeMarkdownManager: Handles intelligent file merging
- ContentOrchestrator: Manages parallel scraper execution
Data Flow
1. Scraper fetches content (checks state for incremental)
2. CumulativeMarkdownManager loads existing file
3. Merges new content (adds new, updates existing)
4. Archives previous version
5. Saves updated file with current timestamp
6. Updates state for next run
Directory Structure
data/
├── markdown_current/ # Current single-source-of-truth files
├── markdown_archives/ # Historical versions by source
│ ├── YouTube/
│ ├── Instagram/
│ └── ...
├── media/ # Downloaded media files
│ ├── Instagram/ # Instagram images and video thumbnails
│ ├── YouTube/ # YouTube video thumbnails
│ ├── Podcast/ # Podcast episode artwork
│ └── ...
└── .state/ # State files for incremental updates
logs/ # Log files by source
src/ # Source code
tests/ # Test files
API Quota Management
YouTube Data API v3
- Daily Limit: 10,000 units
- Usage Strategy: 95% daily quota for captions
- Costs:
- videos.list: 1 unit
- captions.list: 50 units
- channels.list: 1 unit
Rate Limiting
- Instagram: 200 posts/hour
- YouTube: Respects API quotas
- General: Exponential backoff with retry
Production Deployment
Systemd Services
Services are configured in /etc/systemd/system/:
hkia-content-images-8am.service- Morning run with image downloadshkia-content-images-12pm.service- Noon run with image downloadshkia-content-images-8am.timer- Morning schedule (8 AM Atlantic)hkia-content-images-12pm.timer- Noon schedule (12 PM Atlantic)
Manual Deployment
# Start services
sudo systemctl start hkia-content-8am.timer
sudo systemctl start hkia-content-12pm.timer
# Enable on boot
sudo systemctl enable hkia-content-8am.timer
sudo systemctl enable hkia-content-12pm.timer
# Check status
sudo systemctl status hkia-content-*.timer
Monitoring
# View logs
journalctl -u hkia-content-8am -f
# Check file growth
ls -lh data/markdown_current/
# View statistics
uv run python -c "from src.cumulative_markdown_manager import CumulativeMarkdownManager; ..."
Testing
# Run all tests
uv run pytest
# Test specific scraper
uv run pytest tests/test_youtube_scraper.py
# Test cumulative mode
uv run python test_cumulative_mode.py
Troubleshooting
Common Issues
- Instagram Rate Limiting: Scraper implements humanized delays (18-22 seconds between requests)
- YouTube Quota Exceeded: Wait until next day, quota resets at midnight Pacific
- NAS Permission Errors: Warnings are normal, files still sync successfully
- Missing Captions: Use YouTube Data API instead of youtube-transcript-api
Debug Commands
# Check scraper state
cat data/.state/*_state.json
# View recent logs
tail -f logs/YouTube/youtube_*.log
# Test single source
uv run python -m src.youtube_api_scraper_v2 --test
Recent Updates (2025-08-19)
Comprehensive Image Downloading
- Implemented full image download capability for all content sources
- Instagram: Downloads all post images, carousel images, and video thumbnails
- YouTube: Automatically fetches highest quality video thumbnails
- Podcasts: Downloads episode artwork and thumbnails
- Consistent naming:
{source}_{item_id}_{type}.{ext} - Media organized in
data/media/{source}/directories
File Naming Standardization
- Migrated to project specification compliant naming
- Format:
<brandName>_<source>_<dateTime>.md - Example:
hkia_instagram_2025-08-19T100511.md - Archived legacy file structures to
markdown_archives/legacy_structure/
Instagram Backlog Expansion
- Completed initial 1000 posts capture with images
- Currently capturing posts 1001-2000 with rate limiting
- Cumulative markdown updates every 100 posts
- Full image download for all historical content
Production Automation
- Deployed systemd services for twice-daily runs (8 AM, 12 PM Atlantic)
- Automated NAS synchronization for markdown and media files
- Rate-limited scraping with humanized delays (10-20 seconds per Instagram post)
License
Private repository - All rights reserved