-
-
Save saitohirga/95c43b9935d72b22d62cdd975d14ed4b to your computer and use it in GitHub Desktop.
/r/upvoteexeggutor full subreddit generator script
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
Pillow | |
praw==3.4.0 |
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 python3 | |
# This file is licensed under the WTFPL: http://www.wtfpl.net/txt/copying/ | |
import argparse | |
from praw import Reddit | |
from urllib.request import urlopen | |
from PIL import Image | |
DOWNLOAD_LIMIT = 5000 | |
def vstitch_images(images): | |
max_width = max(i.size[0] for i in images) | |
total_height = sum(i.size[1] for i in images) | |
result = Image.new('RGB', (max_width, total_height)) | |
y = 0 | |
for i in images: | |
result.paste(i, (0, y)) | |
y += i.size[1] | |
return result | |
def prepend_iter(iterator, *elements): | |
yield from iter(elements) | |
yield from iterator | |
def main(): | |
parser = argparse.ArgumentParser(description='Combine images from /r/upvoteexeggutor into one big tree') | |
parser.add_argument('dest', help='The destination file') | |
parser.add_argument('-t', '--top', action='store_true', help='Sort by top of all time, not by hot') | |
args = parser.parse_args() | |
reddit = Reddit(user_agent='/r/upvoteexeggutor generator by /u/kupiakos') | |
subreddit = reddit.get_subreddit('upvoteexeggutor') | |
get_func = subreddit.get_top_from_all if args.top else subreddit.get_hot | |
images = [] | |
processed = set() | |
# Assume one sticky | |
get_iter = prepend_iter(get_func(limit=DOWNLOAD_LIMIT), subreddit.get_sticky()) | |
for n, submission in enumerate(get_iter): | |
if submission.id in processed: | |
continue | |
print('%04d: https://redd.it/%s' % (n, submission.id)) | |
with urlopen(submission.thumbnail) as u: | |
images.append(Image.open(u)) | |
processed.add(submission.id) | |
print('Read', len(images), 'images') | |
result = vstitch_images(images) | |
print('Saving %dx%d image to %s' % (*result.size, args.dest)) | |
result.save(args.dest) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment