Created
March 5, 2021 08:55
-
-
Save cuongld2/42c5f41e5a8835387e1edcaa8b64081f to your computer and use it in GitHub Desktop.
code to auto publish article to dev.to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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