Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

I was bored, and I wanted to play with the API, so I came up with this little script:

It's coded in Python and has only a single image dependency.

Here is a screenshot:

Screenshot

Here's the source code (it's tiny, so I have no reason to host it on an external site):

import urllib, gzip, cStringIO, simplejson, pynotify, gtk

url = 'http://api.stackoverflow.com/1.0/users/464744' # I would change this, unless you want to monitor my account ;)
connection = urllib.urlopen(url)
response = connection.read()
connection.close()

info = simplejson.load(gzip.GzipFile(fileobj=cStringIO.StringIO(response)))['users'][0]

pynotify.init("PyOverflow")

message = pynotify.Notification("Stack Overflow", "Reputation: " + str(info['reputation']) + "\n" +
                                                  "Number of questions: " + str(info['question_count']) + "\n" +
                                                  "Number of answers: " + str(info['answer_count']) + "\n" +
                                                  "Number of up votes: " + str(info['up_vote_count']) + "\n" +
                                                  "Number of down votes: " + str(info['down_vote_count']) + "\n" +
                                                  "Accept rate: " + str(info['accept_rate']) + "%")

message.set_icon_from_pixbuf(gtk.gdk.pixbuf_new_from_file('icon.png'))
message.show()

And here's the image the script would be looking for:

The icon

As it took me a while to figure out the JSON and API part, I might make a Python API for this, just for fun.

Any suggestions are welcome (don't worry, I will make this thing a bit more versatile)!

share|improve this question
1  
You can pull the logo dynamically as icon_url via stackauth.com/1.0/sites (though you should cache it). –  Kevin Montrose Dec 1 '10 at 6:57
    
Thanks! I'll try that, but I'm not sure if I can pass it as an argument directly into the script. I think I'll have to download it first... –  Blender Dec 1 '10 at 15:09
1  
Try taking a look at StackApplet to see how I implemented image caching in Python using the API. –  Nathan Osman Dec 2 '10 at 1:42
    
Dumb question but why do you need this ... gzip.GzipFile(fileobj=cStringIO.StringIO(response)) –  PhilGo20 Jan 15 '11 at 20:39
    
It's a bit hard to explain, but the response is sent compressed. It's compressed with Gzip, and a quick one-liner is to treat the output as a pseudo-file and "unzip" it. It took me a while to figure out... –  Blender Jan 17 '11 at 5:04
add comment

You must log in to answer this question.

Browse other questions tagged .