Revisions

gist: 185738 Download_button fork
public
Public Clone URL: git://gist.github.com/185738.git
Embed All Files: show embed
karma.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import simplejson
import urllib2
import httplib2
import urllib
 
import sys
 
try:
    f = urllib2.urlopen("http://www.reddit.com/user/your_user/about/.json")
except Exception, e:
    print "link karma: 000"
    print "comment karma: 000"
    sys.exit(0)
 
content = f.read()
 
json = simplejson.loads(content)
 
print "link karma: %s" % json['data']['link_karma']
print "comment karma: %s" % json['data']['comment_karma']
 
new_messages.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import simplejson
import urllib2
import httplib2
import urllib
 
import sys
 
http = httplib2.Http()
 
url = 'http://www.reddit.com/api/login/your_username'
body = {'user': 'your_username',
        'passwd': 'your_password'}
headers = {'Content-type': 'application/x-www-form-urlencoded'}
 
try:
    response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))
except Exception, e:
    print "No Message"
    sys.exit(0)
 
headers = {'Cookie': response['set-cookie']}
url = 'http://www.reddit.com/message/inbox/.json?mark=false'
response, content = http.request(url, 'GET', headers=headers)
 
if response['status'] != '200':
    print "No message"
    sys.exit(0)
 
json = simplejson.loads(content)
 
message = "New Messages!" if filter(lambda ms: ms['data']['new'], json['data']['children']) else "No message"
print message