Created
May 1, 2014 12:45
-
-
Save xjcl/3e260f92987296b25447 to your computer and use it in GitHub Desktop.
A python script that screencaps reddit comment threads. BECAUSE WHY READ A BOOK WHEN YOU'RE OFFLINE??
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
""" | |
USAGE: | |
You need xvfb, python(2), praw and CutyCapt (see below). Simply run this as | |
a normal python script: `python local_reddit.py` | |
CUSTOMIZATION: | |
* change number of screencaps in main() (10 by deafault) | |
* change queried subreddits in main() | |
(query multiple reddits: "askreddit+writingprompts") | |
* get_top() submissions from day/week instead of hot ones (get_hot()) | |
TIME: | |
The script takes about one minute per capture -- this varies strongly | |
by site size -- I dled some 'hot' askreddit threads and some took 10, | |
others 100 seconds. | |
IMPROVE TIME TAKEN: | |
* Save as jpg instead of png. This takes about half a minute each, SO | |
YOU HAVE MORE TIME TO READ /r/masochism ?? | |
""" | |
import shlex | |
import subprocess | |
import logging | |
import datetime | |
import praw | |
"""also you need this script to be in a folder with CutyCapt. | |
or install it properly and change the capture() function below. | |
see http://cutycapt.sourceforge.net/ for install guide.""" | |
# -------- end imports --------- | |
def capture(url="http://www.reddit.com", out="default.png"): | |
"""From StackOverflow: http://stackoverflow.com/questions/10158864/ | |
running-xvfb-and-cutycapt-as-python-subprocess""" | |
cmd = '''xvfb-run --server-args "-screen 0, 500x800x24" | |
./CutyCapt --url={u} --out={o} '''.format(u=url, o=out) | |
proc = subprocess.Popen(shlex.split(cmd)) | |
proc.communicate() | |
def look_at_threads(r, subreddits="AskReddit", limit=10): | |
i = 0 | |
logging.debug("Getting "+str(limit)+" captures from "+subreddits+".") | |
for submission in r.get_subreddit(subreddits).get_hot(limit=limit): | |
capture(submission.url, "'"+str(datetime.datetime.now())+".png"+"'") | |
#capture(submission.url, str(i)+".png") | |
i += 1 | |
logging.debug("Attempted "+str(i)+" total captures.") | |
def main(): | |
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) | |
r = praw.Reddit("local_reddit.py reddit comments capturer by /u/xjcl") | |
look_at_threads(r, subreddits="AskReddit", limit=10) | |
logging.shutdown() | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment