def main(): br = Browser() br.set_handle_robots(False) br.set_handle_refresh(False) br.addheaders = config.USER_AGENT client = pushnotify.get_client(config.NOTIFY_SERVICE, application='StudWeb') client.add_key(config.NOTIFY_APIKEY) d = shelve.open("results.cache") for school in config.SCHOOLS: points, courses = crawl(br, config.BASE_URL + school, school) if config.VERBOSE: printstdout(points, courses) print "Total points: %s" % points # We have points stored before # so lets see if they are different from what we got now. if school in d: if d[school] != points: d[school] = points if config.NOTIFY: client.notify( "Exam results are in, latest course: %s, grade: %s" % (courses[0].get('name', "Unknown"), courses[0].get( 'grade', 'Unknown')), "New exam results") # No points stored before, so let's just store them. else: d[school] = points d.close()
def main(): """This example shows how to set up logging and some sample output. """ logger = logging.getLogger('pushnotify') logger.setLevel(logging.DEBUG) formatter = logging.Formatter('%(name)s-%(levelname)s: %(message)s') handler = logging.StreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) # this is an obviously invalid API Key apikey = '012345678901234567890123456789012345678901234567' client = pushnotify.get_client('nma', application='pushnotify examples') client.add_key(apikey) event = 'logging example' desc = 'testing the logging capabilities of the pushnotify package' # an exception will be raised because the API Key is invalid try: client.notify(desc, event, split=True) except pushnotify.exceptions.ApiKeyError: pass
def test_get_client_nma(self): """Test get_client for type='nma'. """ client = get_client('nma', NMA_DEVELOPER_KEY, 'pushnotify unit tests') self.assertTrue(client._type == 'nma') self.assertTrue(isinstance(client, nma.Client))
def test_get_client_pushover(self): """Test get_client for type='pushover'. """ client = get_client('pushover', PUSHOVER_TOKEN, 'pushnotify unit tests') self.assertTrue(client._type == 'pushover') self.assertTrue(isinstance(client, pushover.Client))
def test_get_client_prowl(self): """Test get_client for type='prowl'. """ client = get_client('prowl', PROWL_PROVIDER_KEY, 'pushnotify unit tests') self.assertTrue(client._type == 'prowl') self.assertTrue(isinstance(client, prowl.Client))
def setUp(self): self.client = get_client('pushover', PUSHOVER_TOKEN, '') for key in PUSHOVER_USER.keys(): self.client.add_key(key, PUSHOVER_USER[key][0]) self.event = 'pushnotify unit tests' self.desc = 'valid notification test for pushnotify'
def setUp(self): self.client = get_client('prowl', PROWL_PROVIDER_KEY, 'pushnotify unit tests') for key in PROWL_API_KEYS: self.client.add_key(key) self.event = 'unit test: test_notify' self.desc = 'valid notification test for pushnotify'
def setUp(self): self.client = get_client('nma', NMA_DEVELOPER_KEY, 'pushnotify unit tests') for key in NMA_API_KEYS: self.client.add_key(key) self.event = 'unit test: test_notify' self.desc = 'valid notification test for pushnotify'
def sendNotification(application, desc, event): if not pushnotifyAvailable: warnings.warn('Pushnotify is required for sending push notifications') return client = pushnotify.get_client('nma', application=application) client.add_key(conf.get('notifymyandroid', 'api_key')) try: client.notify(desc, event, split=True) except: pass
def notify(new_results): print "Notifying new courses" if config.NOTIFY_SERVICE == 'email': client = mail.mail() elif config.NOTIFY_SERVICE in ['nma', 'prowl', 'pushover']: client = pushnotify.get_client(config.NOTIFY_SERVICE, application='StudWeb') client.add_key(config.NOTIFY_APIKEY) text = "New exam results: " for result in new_results: text = text + "Course: %s, grade: %s; " % \ (result.get('name', 'Unknown'), result.get('grade', 'Unknown')) if config.VERBOSE: print "Notiying new course %s" % result['name'] client.notify(text, "New exam results") print ""
def notify(self, packet): for label, settings in self.config.items(__name__): notifier, apikey = settings.split(',') client = pushnotify.get_client(notifier, packet.headers['Application-Name']) if not client: logger.error('Error loading push provider %s', notifier) return logger.info('Sending push to %s with %s', label, notifier) kwargs = {} for key, target in self._kwargs.items(): if key in packet.headers: kwargs[target] = packet.headers[key] client.add_key(apikey) client.notify(packet.headers['Notification-Text'], packet.headers['Notification-Title'], kwargs=kwargs)
def main(): pushtype = os.environ.get('pushtype', '') pushkey = os.environ.get('pushkey', '') repos = 'bigcompany/hook.io-sdk' compare = 'pyhedgehog:master...dev' url = 'https://api.github.com/repos/%s/compare/%s' % (repos, compare) html_url = 'https://github.com/%s/compare/%s' % (repos, compare) r = requests.get(url) r.raise_for_status() o = r.json() if not o['files']: return 0 # html_url = o['permalink_url'] html_url = o['html_url'] desc1, desc2, desc3 = [], [], dict(files=0, additions=0, deletions=0) for f in o['files']: if f['status'] == 'modified': desc1.append('{filename} (+{additions}, -{deletions})'.format(**f)) else: desc1.append('{filename} ({status})'.format(**f)) desc2.append('{filename} ({status})'.format(**f)) desc3['files'] += 1 desc3['additions'] += f['additions'] desc3['deletions'] += f['deletions'] desc = ', '.join(desc1) if len(desc) > maxdesc: desc = '+{additions}, -{deletions}: '.format(**desc3) + (', '.join(desc2)) if len(desc) > maxdesc: desc = '{files}: +{additions}, -{deletions}'.format(**desc3) if r.text and pushnotify and pushtype and pushkey: client = pushnotify.get_client(pushtype, 'hookiosdksyncmon') client.add_key(pushkey) client.notify(desc, repos + ' update', False, dict(url=html_url)) else: print('\n'.join('diff --git {filename}\n{patch}\n'.format(**f) .replace('\n\\ No newline at end of file', '') for f in o['files'] if 'patch' in f)) print(desc) print(html_url) return 1
def notify(self, packet): for label, settings in self.config.items(__name__): notifier, apikey = settings.split(',') client = pushnotify.get_client( notifier, packet.headers['Application-Name']) if not client: logger.error('Error loading push provider %s', notifier) return logger.info('Sending push to %s with %s', label, notifier) kwargs = {} for key, target in self._kwargs.items(): if key in packet.headers: kwargs[target] = packet.headers[key] client.add_key(apikey) client.notify( packet.headers['Notification-Text'], packet.headers['Notification-Title'], kwargs=kwargs )
def setup_notifier(api, api_key, title): """Set up a notifier with the given api, api_key and title; return a notifier instance""" push_client = pushnotify.get_client(api, application=title) push_client.add_key(api_key) return push_client
def alert_pushnotify(alert, metric): import pushnotify client = pushnotify.get_client(settings.PUSHNOTIFY_OPTS['protocol'], application='skyline') for x in settings.PUSHNOTIFY_OPTS['keys']: client.add_key(x) client.notify("%s (value: %s)" % (metric[1], metric[0]), "Anomalous metric")
def __init__(self, developerkey, application): self.client = pushnotify.get_client('nma', application=application) self.client.add_key(self.apikey)