Last active
July 5, 2022 01:18
-
-
Save alexwlchan/4502860fd9ff014dc178 to your computer and use it in GitHub Desktop.
A Python script for finding untagged posts on Tumblr. See http://alexwlchan.net/2013/08/untagged-tumblr-posts/
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
#!/usr/bin/env python | |
import urllib2 | |
import json | |
HOSTNAME = "example.tumblr.com" | |
API_KEY = "abcdefg" | |
URL = "http://api.tumblr.com/v2/blog/{host}/posts?api_key={key}".format(host=HOSTNAME, key=API_KEY) | |
def api_response(URL): | |
req = urllib2.urlopen(URL) | |
return json.loads(req.read()) | |
# The Tumblr API returns posts in batches of 20, so first we need to | |
# work out how many such batches are required. | |
jsonresponse = api_response(URL) | |
post_count = jsonresponse["response"]["total_posts"] | |
increments = (post_count + 20) / 20 | |
# For each batch of 20, get the results from the Tumblr API, get the | |
# posts and look for any which are untagged. | |
for i in range(increments): | |
jsonresponse = api_response("{url}&offset={count}".format(url=URL, count=i * 20)) | |
posts = jsonresponse["response"]["posts"] | |
for post in posts: | |
if not post["tags"]: | |
print post["post_url"] | |
print "All finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment