def main(): if len(sys.argv) == 1: infile = sys.stdin outfile = sys.stdout elif len(sys.argv) == 2: infile = open(sys.argv[1], 'r') outfile = sys.stdout elif len(sys.argv) == 3: infile = open(sys.argv[1], 'r') outfile = open(sys.argv[2], 'w') else: raise SystemExit(sys.argv[0] + " [infile [outfile]]") with infile: try: obj = json.load(infile, object_pairs_hook=json.OrderedDict, use_decimal=True) except ValueError: raise SystemExit(sys.exc_info()[1]) with outfile: json.dump(obj, outfile, sort_keys=True, indent=' ', use_decimal=True) outfile.write('\n')
def _sendNotifo(self, msg, title, username, apisecret, label="SickBeard"): """ Sends a message to notify using the given authentication information msg: The string to send to notifo title: The title of the message username: The username to send it to apisecret: The API key for the username label: The label to use for the message (optional) Returns: True if the message was delivered, False otherwise """ # tidy up the message msg = msg.strip() # build up the URL and parameters apiurl = API_URL % {"username": username, "secret": apisecret} data = urllib.urlencode({ "title": title, "label": label, "msg": msg.encode(sickbeard.SYS_ENCODING) }) # send the request to notifo try: data = urllib.urlopen(apiurl, data) result = json.load(data) except ValueError, e: logger.log(u"Unable to decode JSON: " + repr(data), logger.ERROR) return False
def _sendNotifo(self, msg, title, username, apisecret, label="SickBeard"): msg = msg.strip() apiurl = API_URL % {"username": username, "secret": apisecret} data = urllib.urlencode({ "title": title, "label": label, "msg": msg }) try: data = urllib.urlopen(apiurl, data) result = json.load(data) except ValueError, e: logger.log(u"Unable to decode JSON: "+data, logger.ERROR) return False
def _sendNotifo(self, msg, title, username, apisecret, label="SickBeard"): msg = msg.strip() apiurl = API_URL % {"username": username, "secret": apisecret} data = urllib.urlencode({ "title": title, "label": label, "msg": msg.encode(sickbeard.SYS_ENCODING) }) try: data = urllib.urlopen(apiurl, data) result = json.load(data) except ValueError, e: logger.log(u"Unable to decode JSON: "+data, logger.ERROR) return False
def main(): if len(sys.argv) == 1: infile = sys.stdin outfile = sys.stdout elif len(sys.argv) == 2: infile = open(sys.argv[1], 'rb') outfile = sys.stdout elif len(sys.argv) == 3: infile = open(sys.argv[1], 'rb') outfile = open(sys.argv[2], 'wb') else: raise SystemExit(sys.argv[0] + " [infile [outfile]]") try: obj = simplejson.load(infile) except ValueError, e: raise SystemExit(e)
def _sendNotifo(self, msg, title, username, apisecret, label="SickBeard"): msg = msg.strip() apiurl = API_URL % {"username": username, "secret": apisecret} data = urllib.urlencode({"title": title, "label": label, "msg": msg}) try: data = urllib.urlopen(apiurl, data) result = json.load(data) except IOError: return False data.close() if result["status"] != "success" or result["response_message"] != "OK": return False else: return True
def main(): if len(sys.argv) == 1: infile = sys.stdin outfile = sys.stdout elif len(sys.argv) == 2: infile = open(sys.argv[1], 'rb') outfile = sys.stdout elif len(sys.argv) == 3: infile = open(sys.argv[1], 'rb') outfile = open(sys.argv[2], 'wb') else: raise SystemExit(sys.argv[0] + " [infile [outfile]]") try: obj = json.load(infile, object_pairs_hook=json.OrderedDict, use_decimal=True) except ValueError, e: raise SystemExit(e)
def _sendNotifo(self, msg, username, apisecret): msg = msg.strip() apiurl = API_URL % {"username": username, "secret": apisecret} data = urllib.urlencode({ "msg": msg, }) try: data = urllib.urlopen(apiurl, data) result = json.load(data) except IOError: return False data.close() if result["status"] != "success" or result["response_message"] != "OK": return False else: return True
def _sendNotifo(self, msg, title, username, apisecret, destination, label="SickBeard"): """ Sends a message to notify using the given authentication information msg: The string to send to notifo title: The title of the message username: The username to send it to apisecret: The API key for the username destination: destination for the message label: The label to use for the message (optional) Returns: True if the message was delivered, False otherwise """ # tidy up the message msg = msg.strip() # build up the URL and parameters apiurl = API_URL % {"username": username, "secret": apisecret} destination = destination.split(',') success = True for dest in destination: data = urllib.urlencode({ "to": dest.strip(), "title": title.encode(sickbeard.SYS_ENCODING), "label": label.encode(sickbeard.SYS_ENCODING), "msg": msg.encode(sickbeard.SYS_ENCODING) }) try: data = urllib.urlopen(apiurl, data) result = json.load(data) data.close() except Exception, e: logger.log(str(e), logger.ERROR) logger.log("Error while sending notification to " + dest, logger.ERROR) success = success or False continue if result["status"] != "success" or result["response_message"] != "OK": success = success or False
def _sendNotifo(self, msg, username, apisecret): msg = msg.strip() apiurl = API_URL % {"username": username, "secret": apisecret} data = urllib.urlencode({ "msg": msg, }) data = urllib.urlopen(apiurl, data) try: try: result = json.load(data) except IOError: return False finally: data.close() if result["status"] != "success" or result["response_message"] != "OK": return False else: return True