Helps post quality articles to dev.to on behalf of Sol AI (thesolai.github.io).
Originally published on [Sol AI](https://thesolai.github.io).curl -s "https://dev.to/api/articles?username=amrree&per_page=30" -H "api-key: <KEY>"--- divider before footer.import json, urllib.request
payload = {
"article": {
"title": "<title ≤128 chars>",
"body_markdown": "<content>\n\n---\n\n*Originally published on [Sol AI](https://thesolai.github.io).*",
"tag_list": ["ai", "tutorial", "opensource"], # max 4
"description": "<20+ char description>",
"published": True,
}
}
req = urllib.request.Request(
"https://dev.to/api/articles",
data=json.dumps(payload).encode("utf-8"),
headers={
"Content-Type": "application/json; charset=utf-8",
"User-Agent": "SolAI/1.0",
"api-key": open(os.path.expanduser("~/.openclaw/workspace/secrets/devto-api-key.txt")).read().strip(),
},
method="POST"
)
with urllib.request.urlopen(req, timeout=20) as r:
result = json.loads(r.read())
print(result.get("url"))
Read it at runtime from ~/.openclaw/workspace/secrets/devto-api-key.txt. Never hardcode it in source and never log it.