Created
October 30, 2013 21:53
-
-
Save ludalex/7240998 to your computer and use it in GitHub Desktop.
Small growl+pushalot notifier for detecting when a user on reedit posts an Hearthstone giveaway thread.
Can apply to any thread if you change URL to check and keywords to detect.
Works only on OSX.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import feedparser | |
import logging | |
logging.basicConfig(level=logging.ERROR) | |
import gntp.notifier | |
import time | |
from httplib import HTTPSConnection | |
from urllib import urlencode | |
def Honk(title, body): | |
http_handler = HTTPSConnection("pushalot.com") | |
data = {'AuthorizationToken': "pushalot_token", | |
'Title': title, | |
'Body': body } | |
http_handler.request("POST", "/api/sendmessage", headers = {'Content-type': "application/x-www-form-urlencoded"}, body = urlencode(data) ) | |
growl.notify( | |
noteType = "New Messages", | |
title = title, | |
description = body, | |
sticky = False, | |
priority = 1, | |
) | |
growl = gntp.notifier.GrowlNotifier( | |
applicationName = "My Application Name", | |
notifications = ["New Updates","New Messages"], | |
defaultNotifications = ["New Messages"], | |
hostname = "localhost", # Defaults to localhost | |
password = "" # Defaults to a blank password | |
) | |
growl.register() | |
honked = {} | |
while True: | |
d = feedparser.parse('http://www.reddit.com/r/hearthstone/new/.rss') | |
title = d.entries[0].title | |
link = d.entries[0].link | |
hotWords = [ "give", "away", "take", "key", "free", "beta" ] | |
found = [i for i, hotWord in enumerate(hotWords) if hotWord.lower() in title.lower()] | |
if found and not honked.get(title): | |
Honk(title, link) | |
honked[title] = True | |
print title | |
else: | |
print "»" | |
time.sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment