def __init__(self, ip=__settings__.getSetting("sabnzbd_ip"), port=__settings__.getSetting("sabnzbd_port"), apikey=__settings__.getSetting("sabnzbd_key"), username=__settings__.getSetting("sabnzbd_user"), password=__settings__.getSetting("sabnzbd_pass"), category=None, use_https=use_https): if not (ip and port and apikey): sabutils.notification("SABnzbd API Error", 1000) raise RuntimeError("Missing, ip, port or API key") self.ip = ip self.port = port self.apikey = apikey if use_https: https_string = "https://" else: https_string = "http://" self.baseurl = https_string + self.ip + ":" + self.port + "/api?apikey=" + apikey if username and password: password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() url = https_string + self.ip + ":" + self.port password_manager.add_password(None, url, username, password) authhandler = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(authhandler) urllib2.install_opener(opener) self.category = category self.kwargs = dict()
def _load_json(url): sabutils.log("SABnzbd: _load_json: url: %s" % url) try: out = json.loads(_load_url(url)) except: sabutils.log("SABnzbd: _load_json: malformed json from url: %s" % url) sabutils.notification("SABnzbd malformed json") return None return out
def _load_xml(url): sabutils.log("SABnzbd: _load_xml: ") try: out = parseString(_load_url(url)) except: sabutils.log("SABnzbd: _load_xml: malformed xml from url: %s" % url) sabutils.notification("SABnzbd malformed xml") return None return out