Created
September 27, 2012 05:20
-
-
Save anacrolix/3792282 to your computer and use it in GitHub Desktop.
Opens front page on reddit for the given subreddit
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
#!/usr/bin/env python3 | |
import argparse | |
import http.cookies | |
import io | |
import json | |
import pprint | |
import urllib.request | |
import webbrowser | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-s', '--sub-reddit') | |
namespace = parser.parse_args() | |
url = 'http://www.reddit.com/' | |
subreddit = namespace.sub_reddit | |
if subreddit is not None: | |
url += 'r/' + subreddit | |
url += '.json' | |
request = urllib.request.Request(url, headers={ | |
'User-Agent': "anacrolix's reddit-open.py",}) | |
response = urllib.request.urlopen(request) | |
browser = webbrowser.get() | |
new = 1 | |
for child in json.load(io.TextIOWrapper(response))['data']['children']: | |
browser.open(child['data']['url'], new) | |
new = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment