DEV Community

S Gr
S Gr

Posted on

How to Build a Self-Updating AI Newsletter Using GitHub Actions and OpenAI API

How to Build a Self-Updating AI Newsletter Using GitHub Actions and OpenAI API

Disclosure: This article contains an affiliate link to a tool I've used. You'll learn a complete method that requires no purchases, and I'll mention one optional paid tool that helped me with email automation.

The Problem with AI Side Hustles in 2026

Most "AI automation" tutorials promise passive income but deliver manual work. After building three failed side projects, I learned that truly automated systems need three things: free infrastructure, reliable APIs, and actual value for subscribers.

This guide shows you how to create a weekly AI-curated newsletter that runs entirely on free tools, using GitHub Actions as your automation engine.

What You'll Build

A newsletter system that:

  • Scrapes trending topics from Hacker News RSS weekly
  • Uses OpenAI API to summarize and curate content
  • Generates a formatted email automatically
  • Sends to subscribers via SendGrid's free tier (100 emails/day)
  • Costs $0.50-$2.00/month in API fees

Prerequisites

  • GitHub account (free)
  • OpenAI API key ($5 credit gets you started)
  • SendGrid account (free tier: 100 emails/day)
  • Basic familiarity with YAML and Python

Step 1: Set Up Your Repository

Create a new GitHub repository named ai-newsletter-automation. Add these files:

ai-newsletter/
├── .github/workflows/weekly-newsletter.yml
├── scripts/
│   ├── fetch_content.py
│   └── generate_newsletter.py
├── subscribers.json
└── requirements.txt
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the Content Fetcher

In scripts/fetch_content.py:

import feedparser
import json
from datetime import datetime, timedelta

def fetch_trending():
    feed = feedparser.parse('https://hnrss.org/frontpage')
    week_ago = datetime.now() - timedelta(days=7)

    articles = []
    for entry in feed.entries[:20]:
        articles.append({
            'title': entry.title,
            'link': entry.link,
            'published': entry.published
        })

    return articles

if __name__ == '__main__':
    articles = fetch_trending()
    with open('trending.json', 'w') as f:
        json.dump(articles, f)
Enter fullscreen mode Exit fullscreen mode

Step 3: Build the AI Curator

In scripts/generate_newsletter.py:

import json
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])

def generate_summary(articles):
    titles = '\n'.join([f"- {a['title']}" for a in articles])

    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{
            "role": "user",
            "content": f"Summarize these tech articles into 3 key trends with brief explanations (200 words max):\n{titles}"
        }],
        max_tokens=300
    )

    return response.choices[0].message.content

if __name__ == '__main__':
    with open('trending.json', 'r') as f:
        articles = json.load(f)

    summary = generate_summary(articles)

    # Simple HTML template
    html = f"""
    <h2>This Week in Tech</h2>
    <div>{summary}</div>
    <h3>Top Articles:</h3>
    <ul>
    {''.join([f'<li><a href="{a["link"]}">{a["title"]}</a></li>' for a in articles[:5]])}
    </ul>
    """

    with open('newsletter.html', 'w') as f:
        f.write(html)
Enter fullscreen mode Exit fullscreen mode

Step 4: Automate with GitHub Actions

In .github/workflows/weekly-newsletter.yml:

name: Weekly Newsletter

on:
  schedule:
    - cron: '0 9 * * 1'  # Every Monday at 9 AM UTC
  workflow_dispatch:  # Manual trigger for testing

jobs:
  generate-and-send:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.11'

      - name: Install dependencies
        run: |
          pip install openai feedparser sendgrid

      - name: Fetch content
        run: python scripts/fetch_content.py

      - name: Generate newsletter
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        run: python scripts/generate_newsletter.py

      - name: Send via SendGrid
        env:
          SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }}
        run: python scripts/send_email.py
Enter fullscreen mode Exit fullscreen mode

Step 5: Configure Secrets

In your GitHub repository:

  1. Go to Settings → Secrets and variables → Actions
  2. Add OPENAI_API_KEY
  3. Add SENDGRID_API_KEY

Step 6: Manage Subscribers

Create subscribers.json:

{
  "subscribers": [
    {"email": "your-email@example.com", "active": true}
  ]
}
Enter fullscreen mode Exit fullscreen mode

For scaling beyond 100 subscribers, you'll need a proper email system. When I hit that point, I used Perpetual Income 365 to handle the email automation and list management—it integrated well with my existing setup and saved me from building a custom subscriber database. But for starting out, the free SendGrid tier works perfectly.

Step 7: Test and Deploy

  1. Push your code to GitHub
  2. Go to Actions tab
  3. Click "Weekly Newsletter" → "Run workflow"
  4. Check your email in 2-3 minutes

Cost Breakdown (Monthly)

  • GitHub Actions: Free (2,000 minutes/month)
  • OpenAI API: ~$1.50 (4 newsletters × 300 tokens × $0.0015)
  • SendGrid: Free (up to 100 emails/day)
  • Total: $1.50/month

Growing Your Subscriber Base

  1. Share on relevant subreddits (r/programming, r/MachineLearning)
  2. Post weekly summaries on LinkedIn with signup link
  3. Add signup form to your GitHub profile README
  4. Cross-post to dev.to with "Subscribe for weekly version"

Common Issues

Rate limits: Add time.sleep(1) between API calls
Workflow not triggering: Check your cron syntax at crontab.guru
SendGrid blocks: Verify your sender domain

What's Next

Once you have 50+ subscribers, consider:

  • Adding click tracking to see which topics resonate
  • A/B testing subject lines
  • Personalizing content based on subscriber interests
  • Monetizing through relevant affiliate partnerships (with disclosure)

The key is building something that runs without you. This system takes 30 minutes to set up and genuinely requires zero maintenance once deployed.

Final Thoughts

Automation isn't about getting rich quick—it's about building systems that deliver consistent value. This newsletter costs less than a coffee per month and can grow into a real audience asset.

Start small, test with yourself as the only subscriber, and iterate based on what actually works.


Tool mentioned (affiliate link): https://breeze760.perpetualinc.hop.clickbank.net/?tid=devtohowtobuildse

Top comments (0)