-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmedium_deploy.py
More file actions
40 lines (30 loc) · 1.15 KB
/
medium_deploy.py
File metadata and controls
40 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
# Create a new token in https://medium.com/me/settings/ > security and app > integration tokens
# get userId in https://api.medium.com/v1/me
# curl -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" https://api.medium.com/v1/me | jq '.data.id'
# copy the id
MEDIUM_USER_ID = "USER_ID"
MEDIUM_API_URL = f"https://api.medium.com/v1/users/{MEDIUM_USER_ID}/posts"
MEDIUM_TOKEN = "TOKEN"
TITLE = "Java Spring Boot Overriding Environment Variables Guide"
FILE_NAME = "README.md"
def main():
headers = {
"Authorization": f"Bearer {MEDIUM_TOKEN}",
"Content-Type": "application/json",
"Accept": "application/json",
"Accept-Charset": "utf-8"
}
data = {
"title": TITLE,
"contentFormat": "markdown",
"content": open(FILE_NAME, "r").read()
}
response = requests.post(MEDIUM_API_URL, headers=headers, json=data)
if response.status_code == 201:
print("Article published successfully!")
else:
print(f"Error: {response.status_code}")
print(f"Error content: {response.content}")
if __name__ == "__main__":
main()