Skip to content

Commit

Permalink
Implemented notification to NotifyMyWindowsPhone when movie was snatched
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvebn committed Feb 12, 2012
1 parent 3568ea7 commit 7fecf05
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/config/configApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ def initConfig(self):
self.setDefault('NMA', 'devkey', '')
self.setDefault('NMA', 'priority', '0')

self.addSection('NMWP')
self.setDefault('NMWP', 'enabled', False)
self.setDefault('NMWP', 'onSnatch', False)
self.setDefault('NMWP', 'apikey', '')
self.setDefault('NMWP', 'devkey', '')
self.setDefault('NMWP', 'priority', '0')

self.addSection('Twitter')
self.setDefault('Twitter', 'enabled', False)
self.setDefault('Twitter', 'onSnatch', False)
Expand Down
50 changes: 50 additions & 0 deletions app/lib/nmwp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from app.config.cplog import CPLog
import cherrypy
from pynmwp import pynmwp

log = CPLog(__name__)

class NMWP:

app_name = 'CouchPotato'

def __init__(self):
self.enabled = self.conf('enabled')
self.apikey = self.conf('apikey')
self.devkey = self.conf('devkey')
self.priority = self.conf('priority')

def conf(self, options):
return cherrypy.config['config'].get('NMWP', options)

def notify(self,event, message):

if not self.enabled:
return

batch = False

p = pynmwp.PyNMWP()
keys = self.apikey.split(',')
log.info(keys)
p.addkey(keys)
p.developerkey(str(self.devkey))

if len(keys) > 1: batch = True

response = p.push(self.app_name, event, message, priority=self.priority, batch_mode=batch)

for key in keys:
if not response[str(key)]['Code'] == u'200':
log.error('Could not send notification to NotifyMyWindowsPhone (%s). %s' % (key,response[key]['message']))

return response

def test(self, apikey, devkey, priority):

self.enabled = True
self.apikey = apikey
self.devkey = devkey
self.priority = priority

self.notify('CouchPotato Test', 'ZOMG Lazors Pewpewpew')

0 comments on commit 7fecf05

Please sign in to comment.