You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
859 B
37 lines
859 B
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]
|
|
|
|
|