Skip to content

Instantly share code, notes, and snippets.

@haywardgg
Created May 21, 2023 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haywardgg/c86b51c3f527c2f47ac59124e5ae68cf to your computer and use it in GitHub Desktop.
Save haywardgg/c86b51c3f527c2f47ac59124e5ae68cf to your computer and use it in GitHub Desktop.
Python Script that Recyles Old Posts - Bludit
import requests
import datetime
# Bludit API endpoint and authentication token
api_url = 'http://your-bludit-site.com/bl-api'
auth_token = 'your-authentication-token'
# Get the list of pages
response = requests.get(f'{api_url}/pages', headers={'Authorization': auth_token})
pages = response.json()
# Find the last post
last_post = max(pages, key=lambda page: page['date'])
# Get today's date
today = datetime.date.today()
# Update the last post's date and time
last_post['date'] = today.strftime('%Y-%m-%d')
last_post['time'] = datetime.datetime.now().strftime('%H:%M:%S')
# Save the changes
response = requests.put(f'{api_url}/pages/{last_post["key"]}', headers={'Authorization': auth_token}, json=last_post)
# Check the response status
if response.status_code == 200:
print("Last post updated successfully.")
else:
print("Failed to update the last post.")
@haywardgg
Copy link
Author

If anyone can help me make this work, I'd be very grateful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment