commit
7744b56616
@ -0,0 +1,36 @@
|
|||||||
|
import requests # pip install requests
|
||||||
|
import jwt # pip install pyjwt
|
||||||
|
from datetime import datetime as date
|
||||||
|
|
||||||
|
# Admin API key goes here
|
||||||
|
key = ''
|
||||||
|
|
||||||
|
# Split the key into ID and SECRET
|
||||||
|
id, secret = key.split(':')
|
||||||
|
|
||||||
|
# Prepare header and payload
|
||||||
|
iat = int(date.now().timestamp())
|
||||||
|
|
||||||
|
header = {'alg': 'HS256', 'typ': 'JWT', 'kid': id}
|
||||||
|
payload = {
|
||||||
|
'iat': iat,
|
||||||
|
'exp': iat + 5 * 60,
|
||||||
|
'aud': '/admin/'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create the token (including decoding secret)
|
||||||
|
token = jwt.encode(payload, bytes.fromhex(secret), algorithm='HS256', headers=header)
|
||||||
|
headers = {'Authorization': 'Ghost {}'.format(token)}
|
||||||
|
url = 'https://ghost.example.com/ghost/api/admin/posts/'
|
||||||
|
|
||||||
|
def deletePost(id):
|
||||||
|
r = requests.delete(url + id + '/', headers=headers)
|
||||||
|
print(r)
|
||||||
|
|
||||||
|
r = requests.get(url + '?limit=all', headers=headers)
|
||||||
|
|
||||||
|
posts = r.json()['posts']
|
||||||
|
|
||||||
|
[deletePost(post['id']) for post in posts]
|
||||||
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
|||||||
|
import requests # pip install requests
|
||||||
|
import jwt # pip install pyjwt
|
||||||
|
from datetime import datetime as date
|
||||||
|
|
||||||
|
# Admin API key goes here
|
||||||
|
key = ''
|
||||||
|
|
||||||
|
# Split the key into ID and SECRET
|
||||||
|
id, secret = key.split(':')
|
||||||
|
|
||||||
|
# Prepare header and payload
|
||||||
|
iat = int(date.now().timestamp())
|
||||||
|
|
||||||
|
header = {'alg': 'HS256', 'typ': 'JWT', 'kid': id}
|
||||||
|
payload = {
|
||||||
|
'iat': iat,
|
||||||
|
'exp': iat + 5 * 60,
|
||||||
|
'aud': '/admin/'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create the token (including decoding secret)
|
||||||
|
token = jwt.encode(payload, bytes.fromhex(secret), algorithm='HS256', headers=header)
|
||||||
|
|
||||||
|
# Make an authenticated request to push an image
|
||||||
|
|
||||||
|
url = 'https://mary.joefix.it/ghost/api/admin/images/upload/'
|
||||||
|
headers = {'Authorization': 'Ghost {}'.format(token)}
|
||||||
|
|
||||||
|
with open("test.jpg", "rb") as file:
|
||||||
|
files = {'file': ('test.jpg', file, 'image/jpeg')}
|
||||||
|
r = requests.post(url, files=files, headers=headers)
|
||||||
|
|
||||||
|
print(r.json())
|
||||||
|
|
Loading…
Reference in new issue