EnglishEN

Blog automation with Claude: turn a list of search terms into several blog drafts (a person publishes)

Build a Python file that takes a file with one search term per line and has Claude write one draft per search term into a drafts folder. A person reads the drafts, edits them, adds their own experience and publishes.

Where to goTerminalplatform.claude.comblog folder

Steps

  1. A blog post has four stages. Choosing the search term is the person's job, writing the draft (outline, subheadings, opening sentences) is Claude's, checking facts and adding your own experience and photos is the person's, and publishing is the person's too. The place people get stuck longest is usually «writing the first line on a blank screen», so handing off just that part cuts the time it takes to write a post. All you need is the Claude API key from part 2 and the Python you installed in part 3.
    keywords.txt                            drafts/
    how to choose a stay in east Jeju   →   how to choose a stay in east Jeju.md
    how long to walk a dog              →   how long to walk a dog.md
  2. Create a working folder and a venv (a work box), then install the Claude library (Mac). On Windows, use python -m venv .venv and .venv\Scripts\activate instead. When you see (.venv) at the start of the line, you are inside the box.
    mkdir blog && cd blog
    python3 -m venv .venv
    source .venv/bin/activate
    pip install -U anthropic
  3. Put the Claude API key you made in part 2 into an environment variable. On a Mac it lasts only in the window you have open now. On Windows, enter setx ANTHROPIC_API_KEY "YOUR_KEY_HERE" and then open a new command window so it gets read. Before running anything, set a monthly spend limit in the Claude Console. Go to «Spend limit» under «Spend and usage» and click «Adjust limit» (part 2). Even if you add lots of search terms, spending will not go past that limit.
    export ANTHROPIC_API_KEY="YOUR_KEY_HERE"
  4. Create keywords.txt in the blog folder and write one search term per line. Try two or three lines first. Each search term becomes a file name as is, so leave out characters like / \ : ? * " < > |. Windows does not allow these characters in file names.
    how to choose a stay in east Jeju
    how long to walk a dog
  5. You can use the code below as it is, or ask Claude to rewrite it to fit how you work. In that case, ask like this.
    Please write a Python blog draft script.
    - Read keywords.txt line by line, and for each line make a draft with the Claude API (the anthropic library).
    - Read the request text from prompt.txt and replace {keyword} in it with the search term.
    - Save the result as drafts/<keyword>.md, and skip files that already exist.
    - Read the key from the ANTHROPIC_API_KEY environment variable; if it is missing, stop right away and say so.
    - If a draft is cut off at the length limit, say so on screen.
  6. Create drafts.py in the blog folder and paste the code in. Drafts that already exist are skipped, so if you add more search terms and run it again, you are not charged twice for drafts you already made. To get one draft again, delete just that file and run it again.
    import os
    import pathlib
    
    import anthropic
    
    MODEL = os.environ.get("CLAUDE_MODEL", "claude-opus-5-5")
    
    if not os.environ.get("ANTHROPIC_API_KEY"):
        raise SystemExit("The ANTHROPIC_API_KEY environment variable is not set. Do section 2, «Add the key», first.")
    
    prompt = pathlib.Path("prompt.txt").read_text(encoding="utf-8")
    keywords = pathlib.Path("keywords.txt").read_text(encoding="utf-8").splitlines()
    
    client = anthropic.Anthropic()  # Reads the ANTHROPIC_API_KEY environment variable
    out = pathlib.Path("drafts")
    out.mkdir(exist_ok=True)
    
    for kw in keywords:
        kw = kw.strip()
        if not kw:
            continue
        f = out / f"{kw}.md"
        if f.exists():
            print("Skipped", f)
            continue
        res = client.messages.create(
            model=MODEL,
            max_tokens=8000,
            messages=[{"role": "user", "content": prompt.replace("{keyword}", kw)}],
        )
        text = "".join(b.text for b in res.content if b.type == "text")
        f.write_text(text, encoding="utf-8")
        if res.stop_reason == "max_tokens":
            print("Created (cut off at the length limit)", f)
        else:
            print("Created", f)
    
  7. Create prompt.txt in the blog folder and paste the text in. By editing only this file, you can change the shape of the drafts without touching the code. If your blog has its own voice, paste a paragraph from one of your past posts at the end and add «Write in this voice».
    Write a blog post draft in English Markdown for someone who arrived by searching “{keyword}”.
    
    - The first line is a one-line title. Work the search term in naturally.
    - In the first paragraph, give the answer this person is looking for first.
    - Use 3~5 subheadings. Put them in the order the searcher will want to know next.
    - Do not make up anything you are not sure of, such as prices, numbers, dates or opening hours; leave [needs checking] instead.
    - Where the writer's own story should go, leave [My experience: your own story here].
    - Where a photo would help, leave [Photo: what the photo shows].
    - Do not use exaggerated wording or stock closing lines.
  8. Check that the three files drafts.py·keywords.txt·prompt.txt are there, then run it. You are done when «Created drafts/….md» shows for each search term and files appear in the drafts folder. Each draft can take a few dozen seconds.
    python drafts.py
  9. When you get a draft, go through it like this. First, find each [needs checking], check it yourself and fill it in. If you cannot confirm it, cut that sentence. Next, write what you went through in the [My experience: …] spots. These spots are what give the post its value. Put photos you took yourself in the [Photo: …] spots. Finally, read it aloud once and fix sentences that do not sound like you. A Naver blog works the same way: open the draft file, paste it into the writing screen, edit, and click publish.

Why we don't hand off publishing too

  • Claude does not know the shops you have been to, the photos you took, or what your customers said. Posts missing these are rated lower by search engines too.
  • Numbers, prices and dates written by AI can be wrong. A person has to check once before publishing.

Pricing

  • The Claude API charges for what you use. Prices are per million tokens.
  • Opus 5.5 (claude-opus-5-5): input $4 · output $20
  • Haiku 5.5 (claude-haiku-5-5): input $0.10 · output $0.50 (price for inputs up to a hundred thousand tokens, per million tokens)
  • The code caps the output at 8,000 tokens, so by the prices above the output cost of one draft is at most $0.16 with Opus 5.5 and at most $0.004 with Haiku 5.5. The input (the request text) is short, so it costs far less than that.
  • To test with a cheaper model first, before running enter export CLAUDE_MODEL="claude-haiku-5-5" on a Mac, or set CLAUDE_MODEL=claude-haiku-5-5 on Windows.

Worried about «low quality»: what Google and Naver say

Many people worry that posts written with AI will rank lower in search. The guidance from both places says the standard is less «did you use AI» and more «is it useful to people».

Google has said that using AI appropriately is not against its guidelines. But it treats churning out posts through automation to manipulate search rankings as spam. It looks at the quality of the content rather than how it was made.

In its Search Advisor recommendations, Naver advises that when you use AI, you should not stop at simply generating or summarizing, but add the site owner's experience and viewpoint to make it original. Its checklist includes «Did you avoid publishing AI-written text as is?»

It lists mass-producing nearly identical posts from the same template as an example of «mass-generated low-quality content» spam. It says using AI or automation alone is not grounds for filtering, but content judged as spam can be dropped from or ranked low in search results.

In a post on February 28, 2025, the Naver Search blog said it is moving toward using LLMs to evaluate documents, aiming to better filter out automatically generated low-quality posts and ad posts with no real experience behind them.

So here is how this part handles it

  • Do not publish a draft as is. Fill in the [My experience]·[Photo] spots before publishing.
  • Do not publish many posts from the same template in one day. You can make the drafts all at once, but publish them one at a time after editing.
  • Do not publish with [needs checking] still in the text. Wrong numbers lose readers.
  • Even so, nobody can promise search rankings. But this keeps you off the paths the docs above tell you to avoid.

Troubleshooting

  • «The ANTHROPIC_API_KEY environment variable is not set»: you skipped adding the key, opened a different window on a Mac, or did not open a new window after setx on Windows.
  • anthropic.AuthenticationError: Error code: 401 (invalid x-api-key): the key was pasted wrong. Enter it again with no spaces or quotes before or after.
  • FileNotFoundError: [Errno 2] No such file or directory: 'keywords.txt' (or 'prompt.txt'): you ran it outside the blog folder, or a file name is different. Windows Notepad sometimes saves as keywords.txt.txt, so check the extension.
  • ModuleNotFoundError: No module named 'anthropic': you ran it outside the venv box. Activate it so (.venv) shows at the start of the line, then run it.
  • Certificate error on Mac (CERTIFICATE_VERIFY_FAILED): enter export SSL_CERT_FILE=$(python -c "import certifi; print(certifi.where())") and run it again.
  • «Created (cut off at the length limit)»: the draft went over 8,000 tokens. In prompt.txt, cut the number of subheadings or set a length such as «about 2,000 characters».
  • Only «Skipped» shows instead of a draft: a draft with the same name already exists. Delete only the draft files you want to get again.
  • Error saying you hit the spend limit: you used up the monthly limit you set. Raise the limit in the Console or wait until next month.

Next part

That wraps up stage 2. The news email, Telegram bot, sheet sorting and blog drafts you have built so far all run on your computer. From the next part on, stage 3 covers putting them on a server so these automations run every day even with your computer off. The first part builds a table to help you choose between shared hosting and a VPS for your automation.

Source

Related posts