def callback(state): if state: window_controller.open_windows() pushover.send("Fresh Air", "Windows opened!") else: window_controller.close_windows() pushover.send("Fresh Air", "Windows closed!")
def pressed(): if throttle.check(): log.info('Doorbell pressed') sound.play() pushover.send(config.message_text) thingspeak.update() else: log.info('THROTTLING')
def main(): r = urllib.request.urlopen(YOURSHOT_URL).read() soup = BeautifulSoup(r, "html.parser") try: with open("./old_titles.txt", "r") as f: old_titles = set(f.read().split('\n')) # If first time running script, ./old_titles.txt will be created at the end. except FileNotFoundError: old_titles = set() # Assignments are chunked by a div with class assignment-block, # Go through each assignment and grab the title. new_assignments = soup.findAll("div", {"class": "assignment-block"}) new_titles = set() for assignment in new_assignments: title = assignment.findAll("h3")[0].get_text() status = assignment.findAll("a", {"class": "gold"})[0].get_text().strip() new_titles.add(title) # Report if any titles have changed. changed_titles = new_titles - old_titles today = datetime.date.today() if changed_titles: message = "{}: {}".format(today, changed_titles) logging.info(message) send(message) else: send("{}: Nothing new.".format(today)) # Save current titles to be checked against later. with open("./old_titles.txt", "w+") as f: for title in new_titles: f.write(title + "\n")
def device_to_shadow(self, state): pushover.send(_CLIENT_NAME, f"{self._name} {'on' if state else 'off'}!") self._update_hook(state)
@logger.log_with(_LOG) def device_to_shadow(self, state): pushover.send(_CLIENT_NAME, f"{self._name} {'on' if state else 'off'}!") self._update_hook(state) if __name__ == "__main__": with GardenController() as garden_controller: iot = IoTCoreClient() for endpoint, zone in garden_controller.get_zones().items(): friendly_name = zone['friendly_name'] adapter = DeviceAdapter(endpoint, friendly_name, garden_controller) shadow_update = iot.create_shadow_handler(endpoint, adapter.shadow_to_device) adapter.set_update_hook(shadow_update) garden_controller.set_update_hook(endpoint, adapter.device_to_shadow) _LOG.info(f"Created handler for {friendly_name}") pushover.send(_CLIENT_ID, "Listener started") try: while True: time.sleep(1) except KeyboardInterrupt: pass
#!/usr/bin/env python import os import argparse import pushover API_TOKEN = os.environ['PUSHOVER_API_TOKEN'] USER_TOKEN = os.environ['PUSHOVER_USER_TOKEN'] parser = argparse.ArgumentParser() parser.add_argument("message", help="the message to send") parser.add_argument("-u", "--url", help="an optional url") args = parser.parse_args() params = {'token': API_TOKEN, 'user': USER_TOKEN, 'message': args.message} if args.url: params['url'] = args.url resp = pushover.send(**params) if resp['status'] == 1: print 'sent!' else: print 'failed: %s' % resp
def send(self, msg): pushover.send(msg) return True