-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
30 lines (26 loc) · 938 Bytes
/
cli.py
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
import click
import requests
from config import settings
@click.command()
@click.option("--title", prompt="Enter the title of the new post", help="Title of the new post")
@click.option("--content", prompt="Enter the content of the new post", help="Content of the new post")
def create_new_post(title, content):
url = f"{settings.FQD}/micropub"
headers = {
"Authorization": f"Bearer {settings.MICROPUB_SECRET}",
"Content-Type": "application/json"
}
data = {
"type": ["h-entry"],
"properties": {
"name": [title],
"content": [content]
}
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 201:
click.echo(f"New post created at {response.json().get('url')}")
else:
click.echo(f"Failed to create post: {response.status_code} {response.text}")
if __name__ == "__main__":
create_new_post()