Пример #1
0
 def history_update(self, source, message):
     self.irc_history.insert(0, (source, message))
     try:
         lookback = utils.get_config("Regex").get("lookback")
     except:
         lookback = 10
     if len(self.irc_history) > int(lookback):
         self.irc_history.pop()
Пример #2
0
 def history_update(self, source, message):
     self.irc_history.insert(0, (source, message))
     try:
         lookback = utils.get_config("Regex").get("lookback")
     except:
         lookback = 10
     if len(self.irc_history) > int(lookback):
         self.irc_history.pop()
Пример #3
0
    def __init__(self, irc):
        self.irc = irc
        self.name = self.__class__.__name__
        self.disabled = False

        try:
            self.redmine = utils.get_config("Redmine")
            self.redmine_domain = self.redmine.get("domain")
            self.redmine_key = self.redmine.get("key")
            self.redmine_url = "https://%s:password@%s" % (
                    self.redmine_key, self.redmine_domain)
        except Exception:
            self.disabled = True
Пример #4
0
    def __init__(self, irc):
        self.irc = irc
        self.name = self.__class__.__name__
        self.disabled = False

        try:
            self.redmine = utils.get_config("Redmine")
            self.redmine_domain = self.redmine.get("domain")
            self.redmine_key = self.redmine.get("key")
            self.redmine_url = "https://%s:password@%s" % (self.redmine_key,
                                                           self.redmine_domain)
        except Exception:
            self.disabled = True
Пример #5
0
    def __init__(self, irc):
        self.irc = irc
        self.name = self.__class__.__name__
        self.disabled = False

        try:
            self.versionone = utils.get_config("VersionOne")
            self.versionone_domain = self.versionone.get("domain")
            self.versionone_key = self.versionone.get("key")
            self.versionone_username = self.versionone.get("username")
            self.versionone_password = self.versionone.get("password")
            self.versionone_url = "https://%s:%s@%s/%s/VersionOne/rest-1.v1" % (
                    self.versionone_username, self.versionone_password,
                    self.versionone_domain, self.versionone_key)
        except Exception:
            self.disabled = True
Пример #6
0
    def __init__(self, irc):
        self.irc = irc
        self.name = self.__class__.__name__
        self.disabled = False

        try:
            self.versionone = utils.get_config("VersionOne")
            self.versionone_domain = self.versionone.get("domain")
            self.versionone_key = self.versionone.get("key")
            self.versionone_username = self.versionone.get("username")
            self.versionone_password = self.versionone.get("password")
            self.versionone_url = ("https://%s:%s@%s/%s/VersionOne/"
                                   "rest-1.v1") % (self.versionone_username,
                                                   self.versionone_password,
                                                   self.versionone_domain,
                                                   self.versionone_key)
        except Exception:
            self.disabled = True
Пример #7
0
    def weather(self, params=None, **kwargs):
        """Display current weather report (ex: .w [set] [<location>])"""
        wunderground = utils.get_config("Wunderground")
        api_key = wunderground.get("key")

        if params:
            location = params
            if location.startswith("set "):
                location = location[4:]
                utils.write_file(self.name, self.irc.source, location)
                self.irc.reply("Location information saved")
        else:
            location = utils.read_file(self.name, self.irc.source)
            if not location:
                self.irc.reply(self.weather.__doc__)
                return

        try:
            w = pywunderground.request(api_key, ["conditions"], location)
        except Exception:
            self.irc.reply("Unable to fetch weather data")
            return

        if w.get("current_observation"):
            w = w["current_observation"]

            city = w["display_location"]["full"]
            zip_code = w["display_location"]["zip"]
            temp = w["temperature_string"]
            heat_index = "%s F (%s C)" % (w["heat_index_f"], w["heat_index_c"])
            humidity = w["relative_humidity"]
            wind = w["wind_string"]
            condition = w["weather"]

            zip_code = "" if zip_code == "00000" else " %s" % zip_code
            humidity = "N/A%" if len(humidity) > 3 else humidity

            result = ("%s%s: [%s / Feels Like: %s]   Humidity: %s   "
                    "Wind: %s   %s") % (city, zip_code, temp, heat_index,
                    humidity, wind, condition)

            self.irc.reply(result)
        else:
            self.irc.reply("Location not found: '%s'" % location)
Пример #8
0
    def __init__(self, irc):
        self.irc = irc
        self.name = self.__class__.__name__
        self.disabled = False
        self._connected = False

        self.severity = ['clear', 'debug', 'info', 'warning', 'error', 'critical']
        self.severitycolor = [15, 13, 11, 8, 5, 40]

        try:
            self.zenoss = utils.get_config("Zenoss")
            self.zenoss_server = self.zenoss.get("server")
            self.zenoss_user = self.zenoss.get("user")
            self.zenoss_password = self.zenoss.get("password")
            self.zenoss_port = self.zenoss.get("port")
            self.zenoss_url = "http://%s:%s" % (self.zenoss_server, self.zenoss_port)
        except Exception:
            self.irc.reply("You need to add a configuration section for [Zenoss].")
            self.disabled = True
Пример #9
0
    def urban(self, params=None, **kwargs):
        """Search Urban Dictionary (ex: .urban <query>)"""
        config = utils.get_config("Urban")

        if not params:
            self.irc.reply(self.urban.__doc__)

        # Check locals first
        entries = json.loads(config.get("local_entries"))
        if entries.get(params):
            self.irc.reply(entries[params])
            return

        query = urllib.urlencode({"term": params})
        url = "http://www.urbandictionary.com/define.php?%s" % query
        response = self.irc.fetch_url(url, self.name)
        if not response:
            return

        soup = BeautifulSoup(response.read())
        results = soup.findAll("div", {"class": "definition"})

        urban = ""
        if len(results):
            urban = " ".join(
                str(x) for x in soup.findAll("div", {"class": "definition"})
                [0].contents)

        if len(urban) > 0:
            for i, line in enumerate(urban.split("<br/>")):
                if i <= 4:
                    self.irc.reply(utils.decode_entities(line))
                else:
                    self.irc.reply("[...] %s" % url)
                    break
        else:
            self.irc.reply("No results found: '%s'" % params)
Пример #10
0
    def urban(self, params=None, **kwargs):
        """Search Urban Dictionary (ex: .urban <query>)"""
        config = utils.get_config("Urban")

        if not params:
            self.irc.reply(self.urban.__doc__)

        # Check locals first
        entries = json.loads(config.get("local_entries"))
        if entries.get(params):
            self.irc.reply(entries[params])
            return

        query = urllib.urlencode({"term": params})
        url = "http://www.urbandictionary.com/define.php?%s" % query
        response = self.irc.fetch_url(url, self.name)
        if not response:
            return

        soup = BeautifulSoup(response.read())
        results = soup.findAll("div", {"class": "definition"})

        urban = ""
        if len(results):
            urban = " ".join(str(x) for x in soup.findAll(
                    "div", {"class": "definition"})[0].contents)

        if len(urban) > 0:
            for i, line in enumerate(urban.split("<br/>")):
                if i <= 4:
                    self.irc.reply(utils.decode_entities(line))
                else:
                    self.irc.reply("[...] %s" % url)
                    break
        else:
            self.irc.reply("No results found: '%s'" % params)
Пример #11
0
 def __init__(self, irc):
     self.irc = irc
     self.name = self.__class__.__name__
     self.config = utils.get_config("Topher")
Пример #12
0
 def __init__(self, irc):
     self.irc = irc
     self.name = self.__class__.__name__
     self.config = utils.get_config("Topher")
Пример #13
0
 def test_get_config(self):
     config = utils.get_config()
     debug = config.get("debug", type="bool")
     self.assertTrue(debug in [True, False])
Пример #14
0
 def test_get_config(self):
     config = utils.get_config()
     debug = config.get("debug", type="bool")
     self.assertTrue(debug in [True, False])