DEV Community

ULNIT
ULNIT

Posted on

How I Built a Cross-Platform Social Media Engine in 300 Lines of Pure Python

You write a product description once. The engine publishes it to Twitter, LinkedIn, Reddit, Threads, and Dev.to — each in the platform's native tone, respecting character limits, formatting conventions, and community norms.

No API keys. No SaaS. No monthly fees. Just Python's standard library and a template engine I can explain in 5 minutes.


🔥 The Hook: Stop Copy-Pasting Across Platforms

Every indie hacker knows the drill: launch a product, then spend 90 minutes reformatting the same announcement for 5 different platforms.

  • Twitter wants punchy 280-char posts with hashtags
  • LinkedIn wants a professional narrative with bullet points
  • Reddit wants a community-focused story that doesn't feel like an ad
  • Threads wants a casual, thread-style opener
  • Dev.to wants a full technical blog post

I got tired of it and built an engine that does it automatically.

🧠 How It Works: A Template Engine with Platform Intelligence

The core idea is dead simple. For each platform, I define:

  1. A character budget (Twitter = 280, LinkedIn = 3000, Reddit = 40000)
  2. Template variants — multiple phrasings per platform, rotated randomly so posts never look repetitive
  3. Formatting rules — bullet points for LinkedIn, markdown headers for Dev.to, hashtags for Twitter

Here's the architecture:

TEMPLATES = {
    "twitter": {
        "max_chars": 280,
        "templates": [
            "🚀 Just shipped: {name}\n\n{oneliner}\n\n{features}\n\n🔗 {url}",
            "I built {name} on a $35 Raspberry Pi 🤯\n\n{oneliner}\n\n✨ {features}\n\n{url}",
        ],
    },
    "linkedin": {
        "max_chars": 3000,
        "templates": [
            """🎉 Excited to share: **{name}**

{oneliner}

**Key Features:**
{features_bullet}

**Why I built this:**
{builder_story}

**Tech Stack:**
🐍 Python stdlib | 🖥️ $35 Raspberry Pi | ⏰ 24/7 Cron

Check it out: {url}

#AI #IndieHacker #BuildInPublic""",
        ],
    },
}
Enter fullscreen mode Exit fullscreen mode

The magic is in {features} vs {features_bullet}. Twitter gets a comma-separated inline list. LinkedIn gets formatted bullet points. Same data, different presentation.

💻 The Engine in Action

Here's the core generation function — 20 lines that do all the heavy lifting:

def generate_post(product, platform):
    t = TEMPLATES.get(platform)
    if not t:
        return {"error": f"Unknown platform: {platform}"}

    template = random.choice(t["templates"])

    # Build platform-appropriate feature strings
    feats = product.get("features", [])
    features_str = ", ".join(f["title"] for f in feats[:4])
    features_bullet = "\n".join(
        f"- **{f['title']}:** {f['desc']}" for f in feats[:5]
    )

    content = template.format(
        name=product["name"],
        oneliner=product["oneliner"],
        features=features_str,
        features_bullet=features_bullet,
        url=product["url"],
    )

    # Enforce character limits
    if len(content) > t["max_chars"]:
        content = content[:t["max_chars"] - 3] + "..."

    return {
        "platform": platform,
        "content": content,
        "char_count": len(content),
    }
Enter fullscreen mode Exit fullscreen mode

Feed it a product definition:

{
  "name": "AI Thumbnail Pro",
  "oneliner": "8 presets. 8 palettes. Auto-generated graphics.",
  "url": "https://github.com/ulnit/ai-thumbnail-pro",
  "features": [
    {"title": "YouTube Ready", "desc": "1280×720 thumbnails"},
    {"title": "Batch Mode", "desc": "All 8 presets in one command"}
  ]
}
Enter fullscreen mode Exit fullscreen mode

And it outputs 5 platform-native posts. Just copy, paste, publish.

🎯 Why This Matters

Content repurposing is the #1 growth hack that nobody automates. Most developers either:

  • Copy-paste the same text everywhere (looks lazy, performs badly)
  • Write custom posts manually (time sink, doesn't scale)

This engine gives you the best of both worlds: platform-native formatting at automation speed.

🐍 Zero Dependencies, Zero Cost

The entire engine is Python's standard library. No pip install. No API keys. No rate limits.

# That's it. No requirements.txt needed.
python3 engine.py --product "AI Video Factory" --output posts.json
Enter fullscreen mode Exit fullscreen mode

I run it on a $35 Raspberry Pi with a cron job. Every product launch automatically generates cross-platform posts while I sleep.

🚀 Real Output Example

Here's what the engine produces for AI Video Factory:

Platform Character Count Tone
Twitter 169/280 Punchy, hashtag-heavy
LinkedIn 568/3000 Professional, story-driven
Reddit 730/40000 Community, build-in-public
Threads 137/500 Casual, thread opener
Dev.to 1384/100000 Full technical blog

Same product. Five platforms. Zero copy-pasting.

📦 Full Source Code

The complete engine (~300 lines) is open source on GitHub:

👉 github.com/ulnit/ai-social-kit

Clone it, add your own products to PRODUCTS_DB, and start automating your content distribution.


🏪 More From This Stack

This is one of 23 AI products running 24/7 on a single $35 Raspberry Pi. No cloud bills. No servers. Pure Python.


If this saved you from another copy-paste marathon, consider buying me a coffee:

👉 paypal.me/ulnit — Any amount helps keep 23 AI products running 24/7! ☕

Top comments (0)