Created
December 6, 2011 12:19
-
-
Save joelthelion/1438003 to your computer and use it in GitHub Desktop.
Get liked items on reddit
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 python2 | |
# coding: utf-8 | |
import json | |
import gzip | |
from StringIO import StringIO | |
from getpass import getpass | |
# Install http://docs.python-requests.org/en/latest/ | |
import requests | |
def reddit_get(url,cookies): | |
req=requests.get(url,cookies=cookies) | |
c_stream=StringIO(req.read()) | |
gzipper=gzip.GzipFile(fileobj=c_stream) | |
return json.loads(gzipper.read()) | |
def reddit_login(): | |
user = raw_input("Enter your reddit user name: ") | |
password = getpass() | |
login = requests.post("http://www.reddit.com/api/login",params={"api_type":"json","user":user,"passwd":password}) | |
return login.cookies | |
cookies = reddit_login() | |
liked = reddit_get("http://www.reddit.com/user/joelthelion/liked/.json",cookies)["data"]["children"] | |
print liked[0] | |
print liked[0]["data"]["title"] | |
print len(liked) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment