DEV Community

Jeffrey.Feillp
Jeffrey.Feillp

Posted on

From Zero to Dev.to Publisher: Building a CLI Tool in Python

From Zero to Dev.to Publisher: Building a CLI Tool in Python

I wanted a way to publish articles to Dev.to from my terminal. No browser, no clicking through forms, just a single command. Here's how I built it.

The Goal

python publish.py --dir ./articles
Enter fullscreen mode Exit fullscreen mode

That's the API I wanted. Give it a directory of markdown files, and it publishes them all to Dev.to.

Step 1: Authentication

Dev.to uses standard Rails authentication. First I needed to log in programmatically:

import requests, re

session = requests.Session()
login_page = session.get('https://dev.to/enter')
csrf = re.search(r'authenticity_token.*?value="([^"]+)"', login_page.text).group(1)

session.post('https://dev.to/users/sign_in', data={
    'user[email]': email,
    'user[password]': password,
    'authenticity_token': csrf,
    'user[remember_me]': '1',
})
Enter fullscreen mode Exit fullscreen mode

Step 2: Getting the Right Token

The tricky part was finding the correct CSRF token for article creation. The dashboard page's token works — you don't need to visit the /new page.

Step 3: Publishing

dashboard = session.get('https://dev.to/dashboard')
csrf = re.search(r'authenticity_token.*?value="([^"]+)"', dashboard.text).group(1)

session.post('https://dev.to/articles', data={
    'authenticity_token': csrf,
    'article[title]': title,
    'article[body_markdown]': body,
    'article[tags]': tags,
    'article[published]': '1',
})
Enter fullscreen mode Exit fullscreen mode

The Complete Tool

I've packaged this into a complete, ready-to-use CLI tool. It handles error recovery, rate limiting, session persistence, and batch processing.

$15 USDT (TRC-20) — one-time purchase.

TNeUMpbwWFcv6v7tYHmkFkE7gC5eWzqbrs
Enter fullscreen mode Exit fullscreen mode

Full details: https://telegra.ph/Devto-Batch-Publisher--15-USDT-One-Time-Purchase-04-29

Top comments (0)