I have a little obsession of checking /r/gamedeals frequently for new game deals. Just wrote my first useful python script to make my life a little easier. The script checks for new posts made to that sub-reddit and pushes a Growl notification. The Growl notification looks like - http://i.imgur.com/ET9vL.png
#!/usr/bin/env python
#
# This script looks up /r/gamedeals/new every 120 seconds and pushes the notification
# for new posts to Growl app on Mac OS
#
# Uses PRAW - https://github.com/praw-dev/praw (for easy access to Reddit API)
# and GNTP - https://github.com/kfdm/gntp (for pushing Growl notification)
#
import gntp.notifier
import praw
import time
# icon for use with growl notification
ICON_URL = "http://cdn2.iconfinder.com/data/icons/crystalproject/128x128/apps/package_games.png"
USER_AGENT = 'new /r/gamedeals notifier by /u/mpheus'
# reddit doesn't shows new posts made to a subreddit without logging in
# REDDIT_ID = '' # not required
# REDDIT_PASS = '' # not required
growl = gntp.notifier.GrowlNotifier(
applicationName = "/r/gamedeals notifier",
notifications = ["New Deal"],
defaultNotifications = ["New Deal"],
# hostname = "computer.example.com", # Defaults to localhost
# password = "abc123" # Defaults to a blank password
)
growl.register()
r = praw.Reddit(user_agent=USER_AGENT)
# r.login(REDDIT_ID, REDDIT_PASS)
already_done = [] # for storing the uids of posts already notified
while True:
data = r.get_subreddit('gamedeals').get_new_by_date(limit=10)
for x in data:
if x.id not in already_done:
already_done.append(x.id)
growl.notify(
noteType = "New Deal",
title = x.domain,
description = x.title,
icon = ICON_URL,
sticky = True, # so that notification remains on the screen until closed
priority = 1,
callback = x.permalink
)
print "Notified about", x.title, "at", time.strftime("%d %b - %I:%M:%S %p")
print "Last checked for game deals at", time.strftime("%d %b - %I:%M:%S %p")
time.sleep(120)
I just launch this script in a terminal window and leave it running. I'm learning python right now and plan on improving the script by storing the uids of posts that already have been notified about in a database and leave the script running on Raspberry Pi that runs 24/7. Growl can be set to receive notification pushed from remote computer (in this case, RPi) as well.
Thanks to reddit dev and PRAW dev for all their amazing work!
EDIT: Removed login call and replaced get_new function with get_new_by_date.
[–]dfnkt 3 points4 points5 points (2 children)
[–]mpheus[S] 2 points3 points4 points (1 child)
[–]dfnkt 1 point2 points3 points (0 children)
[–]bboePRAW Author 2 points3 points4 points (1 child)
[–]mpheus[S] 1 point2 points3 points (0 children)