How aabithgwc/karnataka-project- works
Purpose and entry points
A Python batch pipeline analyzes public YouTube discussion across configured Karnataka regional channels: extract videos/comments, remove non-speech comments, then use Anthropic Claude for translation, sentiment, governance recommendations, and themes.
• Full orchestrator: main.py
• Recent-window extraction runner: extract_last_24h.py
• Channel scope/category input: channels_config.json
• Environment/API configuration: .env.example
Pipeline orchestration
main.py is the control boundary for end-to-end execution. It accepts extraction window, video cap, sampling size, API keys, and an extractor-skip option, then coordinates the three stage entry points. Each stage persists artifacts to its own module-local output/ directory, allowing later stages or reruns to consume saved data.
Paths: main.py, youtube_data_extractor/app.py, data_cleaning/app.py
Stage 1: YouTube multi-channel ingestion
The extractor reads configured channels, resolves each channel’s uploads playlist and metadata, enumerates videos and statistics, and retrieves comment threads/replies. Its YouTube API wrapper centralizes API v3 access and retry behavior; services separate channel, video, and comment collection concerns.
Primary raw boundary: YouTube Data API v3 → structured JSON/CSV datasets.
Paths: youtube_data_extractor/youtube_client.py, youtube_data_extractor/channel_service.py, youtube_data_extractor/comments_service.py
Extraction datasets and time filtering
Extraction writes channel, video, and comment datasets, including recent-window variants. The standalone recent extractor and pipeline --hours flow support bounded collection rather than requiring a full historical run. Downstream cleaning is driven from persisted comment data, not direct API calls.
Paths: extract_last_24h.py, youtube_data_extractor/output/comments.json, youtube_data_extractor/output/comments_last_24h.json
Stage 2: comment quality filtering
Cleaning loads raw comments and filters emoji-only/non-speech text, preserving both accepted comments and rejected records as separate artifacts. This is the boundary that reduces noisy social content before expensive LLM processing.
Paths: data_cleaning/emoji_filter.py, data_cleaning/output/cleaned_comments.json, data_cleaning/output/removed_emoji_only_comments.json
Stage 3: Claude analysis and context enrichment
The sentiment engine samples videos/comments, optionally obtains video subtitles/transcripts for context, and sends Karnataka-tuned prompts with structured result expectations through an Anthropic client. It produces translated English text, sentiment and confidence, reasoning, recommended governance action, thematic tags, and video summaries.
Primary external boundary: cleaned local data/transcripts → Anthropic Claude API → structured analysis results.
Paths: sentiment_analysis/sampler.py, sentiment_analysis/transcript_fetcher.py, sentiment_analysis/sentiment_service.py
Cost, outputs, and additional services
Claude usage is tracked per batch with token/cost logging, making LLM spend an explicit operational concern. Final analytical artifacts and summaries remain filesystem-based. Root-level services and output files indicate an adjacent events/festivals integration and Supabase persistence capability, though they are outside the README’s three-stage core flow.
Paths: sentiment_analysis/usage_tracker.py, sentiment_analysis/output/karnataka_sentiment_results.json, supabase_service.py
Main entry points: sentiment_service.py Sentiment and governance analysis · youtube_client.py YouTube API client · emoji_filter.py Speech quality filter · main.py Pipeline orchestrator
Components 19
Orchestration
- Pipeline orchestrator · Coordinates extraction, cleaning, and analysis with run options.
main.py - Recent-window runner · Runs bounded recent comment extraction.
extract_last_24h.py - Channel scope
channels_config.json
YouTube ingestion
- YouTube Data API v3 · Channel, video, statistics, and comment-thread source.
- YouTube API client · Centralizes API v3 access and retries.
youtube_data_extractor/youtube_client.py - Channel and video collection · Resolves uploads playlists, metadata, and videos.
youtube_data_extractor/channel_service.py - Comment collection · Retrieves comment threads and replies.
youtube_data_extractor/comments_service.py - Raw comments · Persisted full extraction comments.
youtube_data_extractor/output/comments.json - Recent comments · Persisted time-bounded comments.
youtube_data_extractor/output/comments_last_24h.json
Comment cleaning
- Speech quality filter · Separates speech comments from emoji-only or non-speech content.
data_cleaning/emoji_filter.py - Cleaned comments · Accepted input for LLM processing.
data_cleaning/output/cleaned_comments.json - Rejected comments · Audit artifact for removed emoji-only comments.
data_cleaning/output/removed_emoji_only_comments.json
Claude analysis
- Video/comment sampler · Selects analysis input from cleaned persisted data.
sentiment_analysis/sampler.py - Transcript context · Optionally obtains video subtitles and transcripts.
sentiment_analysis/transcript_fetcher.py - Anthropic Claude API · Returns structured translation and governance analysis.
- Sentiment and governance analysis · Builds Karnataka-tuned prompts and structures results.
sentiment_analysis/sentiment_service.py - LLM usage tracking · Logs batch tokens and Claude costs.
sentiment_analysis/usage_tracker.py - Analysis results · Translations, sentiment, actions, themes, and summaries.
sentiment_analysis/output/karnataka_sentiment_results.json
Other components
- Supabase persistence · Adjacent capability outside the core three-stage flow.
supabase_service.py
Connections 23
- Pipeline orchestrator → Channel scope: reads scope
- Pipeline orchestrator → YouTube API client: runs extraction
- Pipeline orchestrator → Speech quality filter: runs cleaning
- Pipeline orchestrator → Sentiment and governance analysis: runs analysis
- Recent-window runner → YouTube API client: runs bounded extraction
- YouTube API client → YouTube Data API v3: API requests
- YouTube API client → Channel and video collection: supports collection
- YouTube API client → Comment collection: supports collection
- Channel scope → Channel and video collection: configured channels
- Channel and video collection → Comment collection: videos
- Comment collection → Raw comments: writes
- Comment collection → Recent comments: writes bounded set
- Raw comments → Speech quality filter: loads
- Recent comments → Speech quality filter: loads recent set
- Speech quality filter → Cleaned comments: writes accepted
- Speech quality filter → Rejected comments: writes rejected
- Cleaned comments → Video/comment sampler: analysis input
- Video/comment sampler → Sentiment and governance analysis: sampled comments
- Transcript context → Sentiment and governance analysis: optional context
- Sentiment and governance analysis → Anthropic Claude API: structured prompts
- Sentiment and governance analysis → LLM usage tracking: token usage
- Sentiment and governance analysis → Analysis results: writes results
- Analysis results → Supabase persistence: optional persistence