Topic Aggregation for Social Media Content
Takes multiple blog URLs on a topic and generates platform-optimized social media posts exported to CSV or Excel.
What this file does
Takes multiple blog URLs on a topic and generates platform-optimized social media posts exported to CSV or Excel.
When to use it
- Building a content calendar from industry news
- Aggregating competitor product launch coverage
- Creating multi-platform posts from research roundups
- Automating social media output for marketing teams
Assumes this stack
Topic Aggregation for Social Media Content
Generate social media-ready content from multiple blog sources on a specific topic, exported to spreadsheet format!
Features
β¨ Batch Summarization - Process multiple URLs concurrently for a specific topic π± Multi-Platform Posts - Generate optimized posts for Twitter, LinkedIn, Facebook, and Instagram π Spreadsheet Export - Export to CSV or Excel with all content organized π― Character-Optimized - Each platform's post respects character limits #οΈβ£ Smart Hashtags - Auto-generated hashtags from topic and content β‘ Concurrent Processing - Fast batch processing with configurable workers
Use Case
Perfect for:
- Social media managers creating content calendars
- Marketing teams tracking industry trends
- Content creators aggregating research
- Brand managers monitoring competitor content
- Digital agencies managing multiple clients
Quick Start
1. API Usage
Aggregate and Get JSON
curl -X POST "http://localhost:8000/aggregate-topic" \
-H "Content-Type: application/json" \
-d '{
"topic": "AI-Trends-2025",
"urls": [
"https://blog.google/technology/ai/",
"https://openai.com/blog/",
"https://www.anthropic.com/news"
],
"platforms": ["twitter", "linkedin", "facebook", "instagram"],
"max_workers": 3
}'
Export to Spreadsheet
curl -X POST "http://localhost:8000/aggregate-topic/export" \
-H "Content-Type: application/json" \
-d '{
"topic": "AI-Trends-2025",
"urls": [
"https://blog.google/technology/ai/",
"https://openai.com/blog/"
],
"platforms": ["twitter", "linkedin", "facebook"],
"export_format": "excel"
}' \
--output AI-Trends-2025_social_media.xlsx
2. Python SDK
from web_summarizer import WebSummarizerAgent
from web_summarizer.topic_aggregator import TopicAggregator
from web_summarizer.spreadsheet_generator import SpreadsheetGenerator
# Initialize
agent = WebSummarizerAgent(gemini_api_key="your_key")
aggregator = TopicAggregator(agent)
spreadsheet_gen = SpreadsheetGenerator()
# Define topic and sources
topic = "AI-Trends-2025"
urls = [
"https://blog.google/technology/ai/",
"https://openai.com/blog/",
"https://www.anthropic.com/news"
]
# Aggregate summaries
result = aggregator.aggregate_topic(
topic=topic,
urls=urls,
platforms=["twitter", "linkedin", "facebook", "instagram"],
max_workers=3
)
# Export to Excel
spreadsheet_gen.generate_excel(
result,
output_path=f"{topic}_social_media.xlsx"
)
3. JavaScript/Browser
const response = await fetch('http://localhost:8000/aggregate-topic/export', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
topic: 'AI-Trends-2025',
urls: [
'https://blog.google/technology/ai/',
'https://openai.com/blog/'
],
platforms: ['twitter', 'linkedin', 'facebook'],
export_format: 'csv'
})
});
// Download the file
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'AI-Trends-2025_social_media.csv';
a.click();
API Endpoints
POST /aggregate-topic
Aggregate summaries and generate social media posts.
Request:
{
"topic": "string",
"urls": ["string"],
"platforms": ["twitter", "linkedin", "facebook", "instagram"],
"max_workers": 5
}
Response:
{
"success": true,
"data": {
"topic": "AI-Trends-2025",
"total_sources": 3,
"successful_summaries": 3,
"failed_summaries": 0,
"platforms": ["twitter", "linkedin", "facebook", "instagram"],
"generated_at": "2025-11-08T10:00:00Z",
"data": [
{
"source_url": "https://example.com",
"title": "Article Title",
"category": "Technology",
"summary": "Summary text...",
"key_points": "Point 1; Point 2; Point 3",
"twitter_post": "Tweet content...",
"twitter_hashtags": "#AI #Tech",
"twitter_chars": 280,
"linkedin_post": "LinkedIn post...",
"linkedin_hashtags": "#AI #Technology",
"linkedin_chars": 500,
...
}
]
}
}
POST /aggregate-topic/export
Aggregate and export to downloadable spreadsheet.
Request:
{
"topic": "string",
"urls": ["string"],
"platforms": ["twitter", "linkedin", "facebook"],
"export_format": "csv" // or "excel"
}
Response: Downloadable CSV or Excel file
Spreadsheet Output
The generated spreadsheet includes:
Columns
- source_url - Original article URL
- title - Article title
- category - Content category
- summary - AI-generated summary
- key_points - Semicolon-separated key insights
- {platform}_post - Social media post content
- {platform}_hashtags - Platform-specific hashtags
- {platform}_chars - Character count
- word_count - Summary word count
- tokens_used - AI tokens consumed
- processing_time_ms - Processing duration
- timestamp - When processed
Excel Features
- Color-coded headers
- Auto-adjusted column widths
- Text wrapping for posts
- Separate metadata sheet
- Frozen header row
- Professional formatting
Platform-Specific Posts
Twitter/X (280 chars)
{First key point or concise summary}
https://example.com/article
#AI #Tech #Innovation
LinkedIn (3000 chars)
π AI Trends 2025: Article Title
{Full summary paragraph}
Key Insights:
1. First key point
2. Second key point
3. Third key point
Read more: https://example.com
#AI #Technology #Innovation #Business #DigitalTransformation
Facebook (~500 chars)
π‘ Article Title
{Summary paragraph}
β¨ Highlights:
β’ First key point
β’ Second key point
β’ Third key point
π https://example.com
#AI #Tech #Innovation
Instagram (2200 chars)
{Summary paragraph}
β¨ Key takeaways:
π First key point
π‘ Second key point
π― Third key point
#AI #Tech #Innovation #Technology #DigitalTransformation #MachineLearning
... (up to 30 hashtags)
Configuration
Platforms
Available platforms:
twitter- Twitter/X (280 char limit)linkedin- LinkedIn (3000 char limit, professional tone)facebook- Facebook (optimized for ~500 chars)instagram- Instagram (2200 char limit, up to 30 hashtags)
Concurrent Workers
max_workers: 1-10 (default: 5)- Higher values = faster processing
- Limited by API rate limits
Export Formats
csv- Comma-separated values (universal compatibility)excel- Microsoft Excel with formatting (.xlsx)
Examples
Example 1: Tech News Roundup
topic = "Weekly-Tech-News"
urls = [
"https://techcrunch.com/latest/",
"https://www.theverge.com/tech",
"https://arstechnica.com/"
]
result = aggregator.aggregate_topic(topic, urls, platforms=["twitter", "linkedin"])
spreadsheet_gen.generate_excel(result, "tech_news_week.xlsx")
Example 2: Competitor Analysis
topic = "Competitor-Product-Launches"
urls = [
"https://competitor1.com/blog/new-product",
"https://competitor2.com/news/launch",
"https://competitor3.com/updates"
]
result = aggregator.aggregate_topic(topic, urls, platforms=["linkedin", "facebook"])
spreadsheet_gen.generate_csv(result, "competitor_analysis.csv")
Example 3: Industry Research
topic = "Climate-Tech-Innovations"
urls = [
"https://example.com/climate-article-1",
"https://example.com/climate-article-2",
"https://example.com/climate-article-3"
]
result = aggregator.aggregate_topic(
topic,
urls,
platforms=["twitter", "linkedin", "facebook", "instagram"],
max_workers=2
)
# Export both formats
spreadsheet_gen.generate_csv(result, "climate_tech.csv")
spreadsheet_gen.generate_excel(result, "climate_tech.xlsx")
Workflow Example
- Research Phase: Find relevant blog posts/articles on your topic
- Aggregate: Run topic aggregation with all URLs
- Review: Open Excel file, review summaries and posts
- Edit: Fine-tune posts if needed directly in spreadsheet
- Schedule: Use spreadsheet to schedule posts on social media platforms
- Track: Keep spreadsheet for content calendar tracking
Performance
- Speed: 3-5 seconds per URL (with Gemini Flash)
- Concurrent: Processes multiple URLs in parallel
- Cost: ~$0.01 per 1000 URLs (with Gemini Flash)
- Success Rate: 95%+ on standard blog posts
Error Handling
Failed URLs are tracked separately:
{
"total_sources": 5,
"successful_summaries": 4,
"failed_summaries": 1
}
Spreadsheet only includes successful summaries. Check response for failure details.
Dependencies
pip install openpyxl>=3.1.0 # For Excel export
(CSV export has no additional dependencies)
Tips
- Topic Naming: Use descriptive, kebab-case names (e.g.,
AI-Trends-2025) - URL Selection: Choose authoritative, well-structured sources
- Platform Mix: Start with 2-3 platforms, expand as needed
- Batch Size: Keep to 5-10 URLs per batch for best performance
- Review Posts: Always review generated posts before publishing
- Custom Hashtags: Edit hashtags in spreadsheet for brand consistency
- Content Calendar: Use timestamp column for scheduling
- A/B Testing: Generate multiple versions with different platforms
Advanced Usage
Custom Post Templates
Extend TopicAggregator to customize post formats:
class CustomAggregator(TopicAggregator):
def _generate_twitter_post(self, summary, key_points, url, hashtags):
# Your custom template
return f"π₯ {key_points[0]}\n\n{url}\n\n{' '.join(hashtags[:2])}"
Filter by Category
Post-process results to filter by category:
result = aggregator.aggregate_topic(topic, urls, platforms=["twitter"])
# Filter only "Technology" category
tech_only = {
**result,
"data": [r for r in result["data"] if r["category"] == "Technology"]
}
spreadsheet_gen.generate_excel(tech_only, "tech_only.xlsx")
Merge Multiple Topics
Combine results from multiple topics:
topic1_result = aggregator.aggregate_topic("AI", urls1, platforms=["twitter"])
topic2_result = aggregator.aggregate_topic("ML", urls2, platforms=["twitter"])
combined = {
"topic": "AI-and-ML",
"data": topic1_result["data"] + topic2_result["data"],
...
}
spreadsheet_gen.generate_excel(combined, "combined.xlsx")
Troubleshooting
Excel file won't open
- Ensure openpyxl is installed:
pip install openpyxl - Check file permissions
Posts too long
- Platform limits are automatically enforced
- Content is truncated with "..."
Missing hashtags
- Hashtags are auto-generated from topic keywords
- Customize in spreadsheet after export
Slow processing
- Reduce
max_workersif hitting rate limits - Process in smaller batches
Swagger Docs
Interactive API documentation: http://localhost:8000/docs
Test the endpoints directly in your browser!
Ready to create amazing social media content from any topic! π
What's inside
6 feature bullets, 3 code examples, 2 API endpoints, 4 platform templates, 3 advanced usage snippets, troubleshooting section
Change this for your project
- Replace
gemini_api_key="your_key"with your actual Gemini API key - Replace
http://localhost:8000with your deployed API base URL - Replace example URLs like
https://blog.google/technology/ai/with your own source URLs
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Separating aggregation logic from spreadsheet generation into distinct classes
- Using a topic-based naming convention (kebab-case) for organizing exports
- Providing both JSON and downloadable file endpoints for the same data
Related Documents
81 - PERSONAL BLOG/WEBSITE DEEP DIVE FOR TECH CREATORS
Compares 6 blog platforms for tech creators and defines 12 content types with SEO, conversion, and social repurpose guidance.
Social Posting & Engagement Analysis
Documents a social media agent's posting, content generation, scheduling, analytics, and memory system with competitor comparisons and ranked improvement opportunities.
Marketing
Provides a collection of 12 prompt templates for marketing, branding, copywriting, and speechwriting tasks, each with step-by-step instructions.
Marketing MCP Servers Integration Guide
Shows how to connect five marketing MCP servers into an automated A2A marketing suite with cross-channel workflows.