Created
June 3, 2023 16:01
-
-
Save ASingleMind/efe9fb8c0dfd99c589c6549c72b4c469 to your computer and use it in GitHub Desktop.
Tumblr Draft Bulk Save and Delete
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 pytumblr | |
import requests | |
# Tumblr API credentials | |
consumer_key = 'YOUR_CONSUMER_KEY' | |
consumer_secret = 'YOUR_CONSUMER_SECRET' | |
oauth_token = 'YOUR_OAUTH_TOKEN' | |
oauth_secret = 'YOUR_OAUTH_SECRET' | |
# Create a Tumblr client | |
client = pytumblr.TumblrRestClient(consumer_key, consumer_secret, oauth_token, oauth_secret) | |
# Get drafts | |
drafts = client.posts('your-blog-identifier.tumblr.com', state='draft') | |
# Loop through drafts and download images | |
for post in drafts['posts']: | |
if 'photos' in post: | |
for photo in post['photos']: | |
url = photo['original_size']['url'] | |
response = requests.get(url, stream=True) | |
if response.status_code == 200: | |
filename = url.split('/')[-1] | |
with open(filename, 'wb') as f: | |
for chunk in response.iter_content(1024): | |
f.write(chunk) | |
print(f"Image downloaded: {filename}") | |
# Delete the draft | |
client.delete_post('your-blog-identifier.tumblr.com', id=post['id']) | |
print(f"Draft deleted: {post['id']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment