Last active
January 19, 2018 09:05
-
-
Save lewdlime/712415f67970ef0778d4983fbbac16d7 to your computer and use it in GitHub Desktop.
Tumblr Following JSON Export
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/python2 | |
import oauth2 | |
import urlparse | |
import pytumblr | |
import json | |
REQUEST_TOKEN_URL = 'http://www.tumblr.com/oauth/request_token' | |
AUTHORIZATION_URL = 'http://www.tumblr.com/oauth/authorize' | |
ACCESS_TOKEN_URL = 'http://www.tumblr.com/oauth/access_token' | |
# To get the Consumer key and Consumer secret, you will need to | |
# register a Tumblr application: https://www.tumblr.com/oauth/apps | |
# Also: You *WILL* need to hard-code the OAuth token and token secret. | |
CONSUMER_KEY = 'CONSUMER_KEY' | |
CONSUMER_SECRET = 'CONSUMER_SECRET' | |
OAUTH_TOKEN = 'OAUTH_TOKEN' | |
OAUTH_TOKEN_SECRET = 'OAUTH_TOKEN_SECRET' | |
# You *WILL* need to have multiple output files generated. | |
following_json = open('following0.json.txt', 'w') | |
consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET) | |
client = oauth2.Client(consumer) | |
resp, content = client.request(REQUEST_TOKEN_URL, "GET") | |
request_token = dict(urlparse.parse_qsl(content)) | |
client = pytumblr.TumblrRestClient( | |
CONSUMER_KEY, CONSUMER_SECRET, | |
OAUTH_TOKEN, OAUTH_TOKEN_SECRET | |
) | |
# If you are like me, and are following 5000 blogs (the maximum allowed), | |
# you will need to offset this script by 1000 blogs for each run, | |
# or have 5 identical scripts to run at those offsets, to total up to 5000. | |
# Each line will contain the next 20 blogs to retrieve through Tumblr's REST | |
# API. Another thing to note is that Tumblr's REST API is very... haphazard. | |
# When a user is following the max allowed of following blogs, it causes a | |
# number of things to break, most notably, any 3rd party services/apps used to | |
# manage a Tumblr account/blogs. You *MAY* need to re-run your script to | |
# get accurate results. If you get status 500 errors, do *NOT* assume that | |
# it's because a blog is unavailable or isnt a legitimate URL. Even on | |
# deactivated accounts, Tumblr will still show REST API data indicating that | |
# account is deactivated. | |
following0 = client.following(offset=0, limit=20) | |
following20 = client.following(offset=20, limit=20) | |
following40 = client.following(offset=40, limit=20) | |
following60 = client.following(offset=60, limit=20) | |
following80 = client.following(offset=80, limit=20) | |
following100 = client.following(offset=100, limit=20) | |
following120 = client.following(offset=120, limit=20) | |
following140 = client.following(offset=140, limit=20) | |
following160 = client.following(offset=160, limit=20) | |
following180 = client.following(offset=180, limit=20) | |
following200 = client.following(offset=200, limit=20) | |
following220 = client.following(offset=220, limit=20) | |
following240 = client.following(offset=240, limit=20) | |
following260 = client.following(offset=260, limit=20) | |
following280 = client.following(offset=280, limit=20) | |
following300 = client.following(offset=300, limit=20) | |
following320 = client.following(offset=320, limit=20) | |
following340 = client.following(offset=340, limit=20) | |
following360 = client.following(offset=360, limit=20) | |
following380 = client.following(offset=380, limit=20) | |
following400 = client.following(offset=400, limit=20) | |
following420 = client.following(offset=420, limit=20) | |
following440 = client.following(offset=440, limit=20) | |
following460 = client.following(offset=460, limit=20) | |
following480 = client.following(offset=480, limit=20) | |
following500 = client.following(offset=500, limit=20) | |
following520 = client.following(offset=520, limit=20) | |
following540 = client.following(offset=540, limit=20) | |
following560 = client.following(offset=560, limit=20) | |
following580 = client.following(offset=580, limit=20) | |
following600 = client.following(offset=600, limit=20) | |
following620 = client.following(offset=620, limit=20) | |
following640 = client.following(offset=640, limit=20) | |
following660 = client.following(offset=660, limit=20) | |
following680 = client.following(offset=680, limit=20) | |
following700 = client.following(offset=700, limit=20) | |
following720 = client.following(offset=720, limit=20) | |
following740 = client.following(offset=740, limit=20) | |
following760 = client.following(offset=760, limit=20) | |
following780 = client.following(offset=780, limit=20) | |
following800 = client.following(offset=800, limit=20) | |
following820 = client.following(offset=820, limit=20) | |
following840 = client.following(offset=840, limit=20) | |
following860 = client.following(offset=860, limit=20) | |
following880 = client.following(offset=880, limit=20) | |
following900 = client.following(offset=900, limit=20) | |
following920 = client.following(offset=920, limit=20) | |
following940 = client.following(offset=940, limit=20) | |
following960 = client.following(offset=960, limit=20) | |
following980 = client.following(offset=980, limit=20) | |
following_list = [ | |
following0, | |
following20, | |
following40, | |
following60, | |
following80, | |
following100, | |
following120, | |
following140, | |
following160, | |
following180, | |
following200, | |
following220, | |
following240, | |
following260, | |
following280, | |
following300, | |
following320, | |
following340, | |
following360, | |
following380, | |
following400, | |
following420, | |
following440, | |
following460, | |
following480, | |
following500, | |
following520, | |
following540, | |
following560, | |
following580, | |
following600, | |
following620, | |
following640, | |
following660, | |
following680, | |
following700, | |
following720, | |
following740, | |
following760, | |
following780, | |
following800, | |
following820, | |
following840, | |
following860, | |
following880, | |
following900, | |
following920, | |
following940, | |
following960, | |
following980 | |
] | |
# Bear in mind that the export will unfortunately contain each set of 20 blogs | |
# as an array, and will also contain the value for the number of blogs | |
# you currently follow. You will need to remove the array brackets around each | |
# set of 20 blogs, and you will also need to remove the number value for how | |
# many blogs you follow, as these make the resulting JSON file invalid. | |
for f in following_list: | |
for val in f.values(): | |
following_json.write(json.dumps(val)) | |
following_json.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment