Browse files

Implemented notification to NotifyMyWindowsPhone when movie was snatched

  • Loading branch information...
1 parent 3568ea7 commit 7fecf05d170fab01c0b1b2779e4a3dda9cfcab22 @yngvebn yngvebn committed Feb 12, 2012
Showing with 57 additions and 0 deletions.
  1. +7 −0 app/config/configApp.py
  2. +50 −0 app/lib/nmwp.py
View
7 app/config/configApp.py
@@ -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)
View
50 app/lib/nmwp.py
@@ -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.