def _get_pb(): if 'PUSHBULLET_KEY' in os.environ: return pushbullet.PushBullet(os.environ['PUSHBULLET_KEY']) password = keyring.get_password("pushbullet", "cli") if not password: raise NoApiKey() return pushbullet.PushBullet(password)
def __init__(self, token): token = str(token) if not token: msg = 'Missing pushbullet API token' raise ValueError(msg) self.pb = pushbullet.PushBullet(token)
def _create_sender(self, token, channel=None): try: bullet = pushbullet.PushBullet(token) sender = bullet # Setup channel object if channel setting is present if channel: for channel_obj in bullet.channels: if channel_obj.channel_tag == channel: sender = channel_obj self._logger.info( "Connected to PushBullet on channel {}".format( channel)) break else: self._logger.warn( "Could not find channel {}, please check your configuration!" .format(channel)) raise NoSuchChannel(channel) self._logger.info("Connected to PushBullet") return bullet, sender except NoSuchChannel: raise except pushbullet.InvalidKeyError: raise except: self._logger.exception("Error while instantiating PushBullet") return None, None
def main(): # initialize system reading for reading environment sysreader = reading.Reading() # get reading from environment reader = sysreader.getReading() # change temp based on env variable temp = os.environ.get('NOTIFICATION_TEMPERATURE', 20) if isinstance(temp, str): try: temp = int(temp) except ValueError: temp = 20 # exit the program if the temperature is more than 20 if (reader["temperature"] > temp): print(reader["temperature"]) sys.exit(0) # Check if another notification exist today try: history = notificationdb.NotificationDB() if (history.checkTodayNotifications() != True): sys.exit(0) except FileNotFoundError: # config file not found print("config file not found. aborting") sys.exit(0) except KeyError: # config file is misconfigured / corrupted print("miconfigured key in config file") sys.exit(0) except (exceptions.InfluxDBClientError, exceptions.InfluxDBServerError) as err: # Exception from influx, print it but proceed to notify the user anyway print(err) # send push bullet notification. It's too cold! devices = [] try: pusher = pushbullet.PushBullet() pusher.pushNotification(reader["temperature"], "cold") devices = pusher.getDevices() except KeyError: print("please check your configuration file") except TypeError: print("cannot decode body") except FileNotFoundError: print("config file not found") except: print("Fail to call pushbullet API") # Write the history for all devices try: history.writeHistory(devices, reader["temperature"], reader["deviceid"]) except (exceptions.InfluxDBClientError, exceptions.InfluxDBServerError) as err: print(err)
def init_pb(): try: # pushbullet = pbullet.Pushbullet({"api_key": api_key}) pb_api = pushbullet.PushBullet(api_key) ch = pb_api.get_channel(channel_tag) return (pb_api, ch) except Exception as e: _log.error("Failed to initialize pushbullet: {}".format(e))
def POST(self): if web.ctx.globals.copy_status['running']: return web.ctx.globals.copy_status['running'] = True data = json.loads(web.data()) web.ctx.globals.copy_status['files'] = len(data['files']) ud = usbdrives() drives = ud.get_usb_drives() for drive in drives: if drive['name'] == data['drive']: if not drive['mountpoint']: mountpoint = "/mnt/ctg" mount = subprocess.call( ["mount", "/dev/" + drive['name'], mountpoint]) else: mountpoint = drive['mountpoint'] break if data['erase']: for x in os.listdir(mountpoint): delpath = os.path.join(mountpoint, x) print("rm " + delpath) shutil.rmtree(delpath) files = data['files'] for f in files: web.ctx.globals.copy_status['files_completed'] += 1 srcfile = f.replace(config.get('AUDIO', 'dir'), '') assert not os.path.isabs(srcfile) dstdir = os.path.join(mountpoint, os.path.dirname(srcfile)) try: os.makedirs(dstdir) print("mkdir " + dstdir) except OSError as exception: if exception.errno != errno.EEXIST or not os.path.isdir( dstdir): raise subprocess.call(["cp", f, dstdir]) print("copy " + f + " to " + dstdir) mount = subprocess.call(["umount", mountpoint]) pb = pushbullet.PushBullet('o.gtkUhglh8LacwQTrJ51ytGECuXy0OfkB') pb.push_note('Copy To-Go', 'Copy finished!') web.ctx.globals.copy_status['running'] = False web.ctx.globals.copy_status['files'] = 0 web.ctx.globals.copy_status['files_completed'] = 0 web.ctx.globals.copy_status['size'] = 0 web.ctx.globals.copy_status['size_completed'] = 0
def __init__(self, conf): super(AutoNotify, self).__init__(conf) # get api key if 'api key' in self.params: self.key = self.params['api key'] elif 'keyring user' in self.params: import keyring import keyrings.alt keyring.set_keyring(keyrings.alt.file.PlaintextKeyring()) self.key = keyring.get_password(*self.params['keyring user']) # init pushbullet self.pb = pushbullet.PushBullet(self.key, proxy=self.params.get('proxy', None))
def main(): # initialize system reading for reading environment sysreader = reading.Reading() # get reading from environment reader = sysreader.getReading() history = None devices = [] sentDevices = [] eligibleMacs = [] # Check if another notification exist today try: history = bluetoothdb.BluetoothDB() devices = history.readDevices() macs = list(map(lambda d: d["MAC"], devices)) # list all macs listed in the config sentDevices = history.getHistory( ) # list all not eligible devices (already sent) eligibleMacs = list( set(macs) - set(sentDevices)) # remove all devices which already been sent devices = list(filter(lambda d: d["MAC"] in eligibleMacs, devices)) # get all eligible devices except FileNotFoundError: # config file not found print("config file not found. aborting") sys.exit(0) except KeyError: # config file is misconfigured / corrupted print("miconfigured key in config file") sys.exit(0) except (exceptions.InfluxDBClientError, exceptions.InfluxDBServerError) as err: # Exception from influx, print it but proceed to notify the user anyway print(err) pusher = None try: pusher = pushbullet.PushBullet() #instantiate pushbullet except KeyError: print("please check your configuration file") except FileNotFoundError: print("config file not found") if (history is not None and len(devices) > 0): # search bluetooth devices search(reader, devices, pusher, history)
def __init__(self, credentials): api_key = credentials.get('api_key') self._api = pushbullet.PushBullet(api_key)
import shutil import errno import pushbullet import ctgconfig web.config.debug = True render = web.template.render('templates/') urls = ('/(.*)/', 'redirect', '/favicon.ico', 'icon', '/', 'index', '/dirtree', 'dirtree', '/usbdrives', 'usbdrives', '/usbdrives/(\w+)', 'usbdrives', '/copy', 'copyFiles') config = ctgconfig.CTGConfig() if config.getboolean('PUSHBULLET', 'send_pushes'): pb = pushbullet.PushBullet(config.get('PUSHBULLET', 'api_key')) def add_global_hook(): g = web.storage({ "copy_status": { "running": False, "files": 0, "files_completed": 0, "size": 0, "size_completed": 0 } }) def _wrapper(handler): web.ctx.globals = g
def check_connection(self): if self.pb is None: self.pb = pushbullet.PushBullet(self.apikey)
def __init__(self, api_key, srv_dev_name, target_name): self.pb = pushbullet.PushBullet(api_key) self.srv = self.get_srv_device(srv_dev_name) self.target = self.find_device_by_name(target_name)
logger.info('Current Balance: %s' % Money( amount=current_idr_balance, currency='IDR').format('id_ID', '¤ #,##0')) with open(NAMA_FILE_DUIT, 'w') as f: f.write(str(current_idr_balance)) if int(profit_idr) == 0: logger.info('Ngepet kali ini unfaedah Bos!!') if int(profit_idr) > 0: message = 'Opit Bos Opit Bos %s' % Money( amount=profit_idr, currency='IDR').format('id_ID', '¤ #,##0') logger.info(message) try: if len(PUSHBULLET_TOKEN) > 0: pb = pushbullet.PushBullet( PUSHBULLET_TOKEN) if PUSHBULLET_TOKEN else None pb.push_note(title='[BABIX] Opit Bos Opit Bos', body=message) except pushbullet.errors.PushbulletError: pass except AttributeError: pass try: if len(TELEGRAM_USER_ID) > 0: telegram = telepot.Bot(TELEGRAM_BOT_TOKEN) telegram.sendMessage(TELEGRAM_USER_ID, '[%s] - %s' % (HOSTNAME, message)) except AttributeError: pass if int(profit_idr) < 0: