Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created September 27, 2012 05:20
Show Gist options
  • Save anacrolix/3792282 to your computer and use it in GitHub Desktop.
Save anacrolix/3792282 to your computer and use it in GitHub Desktop.
Opens front page on reddit for the given subreddit
#!/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