Created
May 21, 2023 14:04
-
-
Save haywardgg/c86b51c3f527c2f47ac59124e5ae68cf to your computer and use it in GitHub Desktop.
Python Script that Recyles Old Posts - Bludit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone can help me make this work, I'd be very grateful :)