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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import httplib2
import json
import sys

def fetch_json(url):
    response, content = httplib2.Http('.cache', timeout=5).request(url)
    if response.status == 200:
        return json.loads(content.decode('utf-8'))['data']

def unread_count(url):
    return len(fetch_json(url + "&mark=false")['children'])

def karma(url):
    username = url.split('=')[2]
    stats = fetch_json('http://reddit.com/user/{0}/about.json'.format(username))
    return username, stats['link_karma'], stats['comment_karma']

def main(url):
    usern, linkk, commentk = karma(url)
    mailc = unread_count(url)
    if mailc == 0:
        print(usern + '${image ~/.conky/nomail.png -p 160,4}')
    else:
        print(usern + '${image ~/.conky/mail.png -p 160,4}${alignr 18}' + str(mailc) + ':')
    print(' Link:$alignr ' + str(linkk))
    print(' Comment:$alignr ' + str(commentk))

if __name__ == '__main__':
    if len(sys.argv) > 0:
        main(sys.argv[1])