Last active
December 17, 2018 22:02
-
-
Save DavidLutton/5e242340fc87e3d0ac69c7c861cab1da to your computer and use it in GitHub Desktop.
Download Tumblr likes
This file contains hidden or 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
| from pprint import pprint | |
| import time | |
| from random import uniform | |
| import pytumblr # https://github.com/tumblr/pytumblr | |
| import requests | |
| ''' | |
| MIT License | |
| Copyright (c) 2018, David Lutton | |
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| ''' | |
| # Authenticate via OAuth | |
| '''client = pytumblr.TumblrRestClient( | |
| '', | |
| '', | |
| '', | |
| '', | |
| )''' | |
| pprint(client.info()) | |
| # This will go through likes in chunks of 50 posts and download all the photos in the original_size | |
| # sleep to avoid rate limit for api request | |
| # no redownload checks wastefull on 1 + n passes | |
| urls = [] | |
| for ranger in range(0, client.info()['user']['likes'], 50): | |
| # for ranger in range(0, 1000, 50): | |
| print('\n\n') | |
| print(ranger) | |
| res = client.likes(limit=50, offset=ranger) | |
| for post in res['liked_posts']: | |
| if post['type'] == 'photo': | |
| for en, x in enumerate(post['photos']): | |
| url = post['photos'][en]['original_size']['url'] | |
| if url not in urls: | |
| urls.append(url) | |
| print(url) | |
| # tim = uniform(0,10) | |
| #print(tim) | |
| # time.sleep(tim) | |
| r = requests.get(url) | |
| with open(url.split('/')[-1], 'wb') as fd: | |
| for chunk in r.iter_content(chunk_size=128): | |
| fd.write(chunk) | |
| else: | |
| print('been here before') | |
| # if post is not None: | |
| # client.unlike(post['id'], post['reblog_key']) | |
| tim = 3 + uniform(0, 30) | |
| print(tim) | |
| time.sleep(tim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment