Skip to content

Instantly share code, notes, and snippets.

@joebo
Created October 8, 2010 16:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebo/617089 to your computer and use it in GitHub Desktop.
Save joebo/617089 to your computer and use it in GitHub Desktop.
"""
A python script to notify on hackernews changes using pySnarl (win32)
author: joebo
I found myself checking HN throughout the day while working and would
spend a few minutes each time skimming to see if there was anything new.
This automated the task for me and I thought it might be useful to share.
It's meant to be quick and dirty but works.
get pysnarl from http://code.google.com/p/pysnarl/
thanks to ihackernews for the api (checks every 120 seconds)
change url to http://api.ihackernews.com/new if you want the new items
"""
import urllib2
import PySnarl
import time
import string
def printable(input):
return filter(lambda x: x in string.printable, input)
seen = set()
firstRun = True
while True:
json = "".join(urllib2.urlopen('http://api.ihackernews.com/page').readlines())
try:
items = eval(json)["items"]
except:
print items
else:
for item in items:
title = printable(item["title"])
if not firstRun and not item["id"] in seen:
PySnarl.snShowMessage('HackerNews', title, timeout=10)
print title
seen.add(item["id"])
firstRun = False
time.sleep(120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment