Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created March 5, 2021 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/42c5f41e5a8835387e1edcaa8b64081f to your computer and use it in GitHub Desktop.
Save cuongld2/42c5f41e5a8835387e1edcaa8b64081f to your computer and use it in GitHub Desktop.
code to auto publish article to dev.to
import json
import requests
class BodyArticle(object):
def __init__(self, title, content, tags, published=False, series=None):
self.title = title
self.published = published
self.body_markdown = content
self.tags = tags
self.series = series
if __name__ == "__main__":
# execute only if run as a script
url = "https://dev.to/api/articles"
title_test = "Second Martin Dinh Test"
content_test = "Hello DEV, test automate API. \n test \n ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxwogjwgl7jm63gebz9v.jpg)"
tags_test = ["test", "api"]
body_article = BodyArticle(title=title_test, content=content_test, tags= tags_test)
this_dict = {"article": body_article.__dict__}
data = json.dumps(this_dict)
result = requests.post(url=url, json=json.loads(data), headers={"api_key": "key"})
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment