def event_info(self): info = OrderedDict() info['con'] = 'Dragon Con' info['url'] = self.site_url info['start'] = self.start info['end'] = self.end return '{0}'.format(jsonify(info))
def sms(ctx, numbers, send_all, message): smtp_login = ctx.obj["config"].get("smtp_login", None) if smtp_login is None: error("cannot send SMS messages until SMTP has been configured") return debug(numbers) debug('message="{0}"'.format(message)) debug(jsonify(smtp_login)) if len(message) > 160: info("converting to multipart message...") return lookups = ctx.obj["config"].get("lookups") if send_all: info("sending to all stored phone numbers...") with EmailSMS(**smtp_login) as smsgw: for num, data in lookups.iteritems(): info("sending to {0}[{1}]".format(data["comment"], data["sms"])) smsgw.send(data["sms"], message) elif len(numbers): info("sending to numbers: {0}".format(numbers)) with EmailSMS(**smtp_login) as smsgw: for num in numbers: data = lookups.get(num, None) if not data: info("WARNING | unknown number: {0}".format(num)) continue info("sending to {0}[{1}]".format(data["comment"], data["sms"])) smsgw.send(data["sms"], message) else: info("no numbers have been selected!")
def lookup(self): log = self.log try: info = carrier_lookup(self.number, self._logger) except ValueError: raise SystemExit() log.debug(jsonify(info)) self._raw = info self._unpack() self._raw["comment"] = self._comment return info
def config(ctx, server, username, passcode): smtp_login = ctx.obj["config"].get("smtp_login", None) if smtp_login is None: ctx.obj["config"]["smtp_login"] = OrderedDict() smtp_login["server"] = None smtp_login["username"] = None smtp_login["passcode"] = None smtp_login = ctx.obj["config"]["smtp_login"] debug(jsonify(ctx.obj["config"]["smtp_login"])) update_config = False if server is not None and server != smtp_login["server"]: smtp_login["server"] = server info("SMTP server set to: {0}".format(server)) update_config = True elif server is not None: info("SMTP server is already set to: {0}".format(server)) if username is not None and username != smtp_login["username"]: smtp_login["username"] = username info("SMTP username set to: {0}".format(username)) update_config = True elif username is not None: info("SMTP username is already set to: {0}".format(username)) if passcode is not None and passcode != smtp_login["passcode"]: smtp_login["passcode"] = passcode info("SMTP passcode set to: {0}".format(passcode)) update_config = True elif passcode is not None: info("SMTP passcode is already set to: {0}".format(passcode)) if not update_config: info("no config changes to write") return with open(CONFIG_FILE, "wb") as config: config.write(jsonify(ctx.obj["config"])) info("\nSMTP settings:") info(" - server = {0}".format(ctx.obj["config"]["smtp_login"]["server"])) info(" - user = {0}".format(ctx.obj["config"]["smtp_login"]["username"])) info(" - pass = {0}".format(ctx.obj["config"]["smtp_login"]["passcode"]))
def dumps(self, constrain=None, pretty=False): info = OrderedDict() if constrain is None or constrain == 'smtp': info['smtp_server'] = self.commdata['smtp_login']['server'] info['smtp_username'] = self.commdata['smtp_login']['username'] if constrain is None or constrain == 'lookups': lookinfo = [] for key in self.commdata['lookups']: person = self.commdata['lookups'][key] lookinfo.append('{0:8} {1} {2}'.format( person['first_name'], person['phone'], person['email'])) info = lookinfo if constrain is None or constrain == 'recipients': info = self.commdata['recipients'] return jsonify(info, pretty=pretty)
def lookup(ctx, number, comment, cache): """Get the carrier and country code for a phone number""" phone = PhoneNumber(number, comment=comment) info("{0} | {1}".format(phone.number, ctx.obj["config"]["lookups"].keys())) if phone.number in ctx.obj["config"]["lookups"]: info("{0} is already cached:".format(phone.number)) info(jsonify(ctx.obj["config"]["lookups"][phone.number])) return data = phone.lookup() info("carrier = {0}".format(phone.carrier)) info("type = {0}".format(phone.type)) info("cache = {0}".format(cache)) if cache: ctx.obj["config"]["lookups"][phone.number] = phone.raw with open(CONFIG_FILE, "wb") as cfg: cfg.write(json.dumps(ctx.obj["config"], indent=2))
def flush(self): if not self._tofile: return with io.open(self.cachefile, 'w', encoding='utf-8') as cf: cf.write(jsonify(self._data, True))
def dumps(self, pretty=False): return jsonify(self.dict(), pretty=pretty)