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
- 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 - Create a working folder and a venv (a work box), then install the Claude library (Mac). On Windows, use
python -m venv .venvand.venv\Scripts\activateinstead. 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 - 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" - Create
keywords.txtin theblogfolder 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 - 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. - Create
drafts.pyin theblogfolder 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) - Create
prompt.txtin theblogfolder 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. - Check that the three files
drafts.py·keywords.txt·prompt.txtare there, then run it. You are done when «Created drafts/….md» shows for each search term and files appear in thedraftsfolder. Each draft can take a few dozen seconds.python drafts.py - 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, orset CLAUDE_MODEL=claude-haiku-5-5on 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
setxon 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 theblogfolder, or a file name is different. Windows Notepad sometimes saves askeywords.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): enterexport 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
- AI automationGetting started with AI automation: Claude vs ChatGPT vs Gemini — which one fits your workAll three have two routes: the chat window and the API. Work a person can paste in each time goes in the chat window; work that must run by itself at a set time or condition goes through the API.4 stepsclaude.ai › chatgpt.com › gemini.google.comRead
- AI automationHow to get a Claude, ChatGPT and Gemini API key, and check pricing and free limitsGet an API key from each company's console with «Create key», and put it in an environment variable instead of writing it in code. Only Gemini has a free tier; ChatGPT and Claude charge for what you use.6 stepsaistudio.google.com/apikey › platform.openai.com/api-keys › platform.claude.com/settings/keysRead
- AI automationGet a daily morning news summary email with the Gemini API: your first Python automationBuild one Python file that collects news headlines, has Gemini summarize them in five lines, and sends the summary to your Gmail. Ask an AI to write the code; this guide only covers how to put it in place and run it.8 stepspython.org › Terminal › myaccount.google.com/apppasswordsRead