Ejemplo n.º 1
0
    def keyword_k(self, message, params=None, **kwargs):
        """Retrieve kernel.org Bugzilla bug information (ex: K12345)"""
        params = utils.ensure_int(params)
        if not params:
            return

        params = {"id": params}
        url = "https://bugzilla.kernel.org/show_bug.cgi"
        response = utils.fetch_url(url, params=params)
        if response.status_code != 200:
            return

        soup = BeautifulSoup(response.content)
        desc = utils.decode_entities(soup.head.title.string)

        try:
            status = soup.find("span", {"id": "static_bug_status"}).string
            status = status.capitalize().split("\n")[0]

            assignee = utils.decode_entities(
                soup.findAll("span", {
                    "class": "vcard"
                })[0].contents[0].string)

            msg = "%s [Status: %s, Assignee: %s] %s"
            message.dispatch(msg % (desc, status, assignee, url))
        except TypeError:
            return
Ejemplo n.º 2
0
    def keyword_k(self, message, params=None, **kwargs):
        """Retrieve kernel.org Bugzilla bug information (ex: K12345)"""
        if params:
            params = utils.ensure_int(params)
            if not params:
                return

            query = urllib.urlencode({"id": params})
            url = "http://bugzilla.kernel.org/show_bug.cgi?%s" % query
            response = self.irc.fetch_url(url, self.name)
            if not response or not isinstance(params, int):
                return

            soup = BeautifulSoup(response.read())
            desc = utils.decode_entities(soup.head.title.string)

            try:
                status = soup.find("span", {"id": "static_bug_status"}).string.strip().capitalize()
                assignee = utils.decode_entities(soup.findAll("span", {"class": "vcard"})[0].contents[0].string)

                msg = "Kernel.org %s [Status: %s, Assignee: %s] %s"
                message.dispatch(msg % (desc, status, assignee, url))

            except TypeError:
                return
Ejemplo n.º 3
0
    def keyword_k(self, message, params=None, **kwargs):
        """Retrieve kernel.org Bugzilla bug information (ex: K12345)"""
        if params:
            params = utils.ensure_int(params)
            if not params:
                return

            query = urllib.urlencode({"id": params})
            url = "http://bugzilla.kernel.org/show_bug.cgi?%s" % query
            response = self.irc.fetch_url(url, self.name)
            if not response or not isinstance(params, int):
                return

            soup = BeautifulSoup(response.read())
            desc = utils.decode_entities(soup.head.title.string)

            try:
                status = soup.find("span", {
                    "id":
                    "static_bug_status"}).string.strip().capitalize()
                assignee = utils.decode_entities(
                    soup.findAll("span", {
                        "class": "vcard"
                    })[0].contents[0].string)

                msg = "Kernel.org %s [Status: %s, Assignee: %s] %s"
                message.dispatch(msg % (desc, status, assignee, url))

            except TypeError:
                return
Ejemplo n.º 4
0
    def imdb(self, message, params=None, **kwargs):
        """Search IMDb (ex: .imdb <query>)"""
        if params:
            query = urllib.urlencode({"q": params})
            url = "http://www.imdb.com/find?s=all&%s" % query
            response = self.irc.fetch_url(url, self.name)
            if not response:
                return

            soup = BeautifulSoup(response.read())
            results = soup.findAll("td", {"valign": "top"})

            i = 0
            for result in results:
                if len(result) > 3 and len(result.contents[2].attrs) > 0:
                    id = result.contents[2].attrs[0][1]
                    title = utils.decode_entities(result.contents[2]
                                                  .contents[0])
                    year = result.contents[2].nextSibling.strip()[0:6]

                    if not title.startswith("aka") and len(year):
                        message.dispatch("%s %s: http://www.imdb.com%s" % (
                                         title, year, id))
                        i += 1
                elif i >= 4:
                    break

            if i == 0:
                message.dispatch("No results found: '%s'" % params)
        else:
            message.dispatch(self.imdb.__doc__)
Ejemplo n.º 5
0
    def urban(self, message, params=None, **kwargs):
        """Search Urban Dictionary (ex: .urban <query>)"""
        if params:
            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:
                        message.dispatch(utils.decode_entities(line))
                    else:
                        message.dispatch("[...] %s" % url)
                        break
            else:
                message.dispatch("No results found: '%s'" % params)
        else:
            message.dispatch(self.urban.__doc__)
Ejemplo n.º 6
0
    def urban(self, message, params=None, **kwargs):
        """Search Urban Dictionary (ex: .urban <query>)"""
        if params:
            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:
                        message.dispatch(utils.decode_entities(line))
                    else:
                        message.dispatch("[...] %s" % url)
                        break
            else:
                message.dispatch("No results found: '%s'" % params)
        else:
            message.dispatch(self.urban.__doc__)
Ejemplo n.º 7
0
    def imdb(self, message, params=None, **kwargs):
        """Search IMDb (ex: .imdb <query>)"""
        if params:
            query = urllib.urlencode({"q": params})
            url = "http://www.imdb.com/find?s=all&%s" % query
            response = self.irc.fetch_url(url, self.name)
            if not response:
                return

            soup = BeautifulSoup(response.read())
            results = soup.findAll("td", {"valign": "top"})

            i = 0
            for result in results:
                if len(result) > 3 and len(result.contents[2].attrs) > 0:
                    id = result.contents[2].attrs[0][1]
                    title = utils.decode_entities(
                        result.contents[2].contents[0])
                    year = result.contents[2].nextSibling.strip()[0:6]

                    if not title.startswith("aka") and len(year):
                        message.dispatch("%s %s: http://www.imdb.com%s" %
                                         (title, year, id))
                        i += 1
                elif i >= 4:
                    break

            if i == 0:
                message.dispatch("No results found: '%s'" % params)
        else:
            message.dispatch(self.imdb.__doc__)
Ejemplo n.º 8
0
    def urban(self, message, params=None, **kwargs):
        """Search Urban Dictionary (ex: .urban <query>)."""
        url = "http://www.urbandictionary.com/define.php"
        response = request.get(url, params={"term": params})
        if response.status_code != 200:
            return

        soup = BeautifulSoup(response.content)

        try:
            meaning = soup.find("div", {"class": "meaning"}).text
            example = soup.find("div", {"class": "example"}).text
        except AttributeError:
            message.dispatch("No results found: '%s'" % params)

        meaning = utils.decode_entities(meaning)
        example = utils.decode_entities(example)

        message.dispatch("%s (ex: %s)" % (meaning, example))
Ejemplo n.º 9
0
Archivo: search.py Proyecto: jk0/pyhole
    def urban(self, message, params=None, **kwargs):
        """Search Urban Dictionary (ex: .urban <query>)."""
        url = "http://www.urbandictionary.com/define.php"
        response = request.get(url, params={"term": params})
        if response.status_code != 200:
            return

        soup = BeautifulSoup(response.content)

        try:
            meaning = soup.find("div", {"class": "meaning"}).text
            example = soup.find("div", {"class": "example"}).text
        except AttributeError:
            message.dispatch("No results found: '%s'" % params)

        meaning = utils.decode_entities(meaning)
        example = utils.decode_entities(example)

        message.dispatch("%s (ex: %s)" % (meaning, example))
Ejemplo n.º 10
0
    def _find_title(self, message, url):
        """Find the title of a given URL."""
        # NOTE(jk0): Slack does some weird things with URLs.
        url = url.replace("<", "").replace(">", "").split("|")[0]
        if not url.startswith(("http://", "https://")):
            url = "http://" + url

        try:
            response = request.get(url)
        except Exception:
            return

        soup = BeautifulSoup(response.content)
        if soup.head:
            title = utils.decode_entities(soup.head.title.string)
            content_type = response.headers.get("Content-Type")
            message.dispatch("%s (%s)" % (title, content_type))
        else:
            message.dispatch("No title found: %s" % url)
Ejemplo n.º 11
0
Archivo: urls.py Proyecto: jk0/pyhole
    def _find_title(self, message, url):
        """Find the title of a given URL."""
        # NOTE(jk0): Slack does some weird things with URLs.
        url = url.replace("<", "").replace(">", "").split("|")[0]
        if not url.startswith(("http://", "https://")):
            url = "http://" + url

        try:
            response = request.get(url)
        except Exception:
            return

        soup = BeautifulSoup(response.content)
        if soup.head:
            title = utils.decode_entities(soup.head.title.string)
            content_type = response.headers.get("Content-Type")
            message.dispatch("%s (%s)" % (title, content_type))
        else:
            message.dispatch("No title found: %s" % url)
Ejemplo n.º 12
0
    def _find_title(self, message, url):
        """Find the title of a given URL"""
        if not url.startswith(("http://", "https://")):
            url = "http://" + url

        response = self.irc.fetch_url(url, self.name)
        if not response:
            return

        soup = BeautifulSoup(response.read())
        if soup.head:
            title = utils.decode_entities(soup.head.title.string)
            content_type = response.headers.get("Content-Type").split(";",
                                                                      1)[0]
            content_size = response.headers.get("Content-Length")
            content_size = content_size + " bytes" if content_size else "N/A"

            message.dispatch("%s (%s, %s)" % (title, content_type,
                             content_size))
        else:
            message.dispatch("No title found for %s" % url)
Ejemplo n.º 13
0
    def twitter(self, message, params=None, **kwargs):
        """Search Twitter (ex: .twitter <query>)"""
        if params:
            query = urllib.urlencode({"q": params, "rpp": 4})
            url = "http://search.twitter.com/search.json?%s" % query
            response = self.irc.fetch_url(url, self.name)
            if not response:
                return

            json_obj = json.loads(response.read())
            results = json_obj["results"]
            if results:
                for r in results:
                    message.dispatch("@%s: %s" % (r["from_user"],
                                     utils.decode_entities(
                                     r["text"].encode("ascii", "ignore"))))

            else:
                message.dispatch("No results found: '%s'" % params)
        else:
            message.dispatch(self.twitter.__doc__)
Ejemplo n.º 14
0
    def _find_title(self, message, url):
        """Find the title of a given URL"""
        if not url.startswith(("http://", "https://")):
            url = "http://" + url

        response = self.irc.fetch_url(url, self.name)
        if not response:
            return

        soup = BeautifulSoup(response.read())
        if soup.head:
            title = utils.decode_entities(soup.head.title.string)
            content_type = response.headers.get("Content-Type").split(";",
                                                                      1)[0]
            content_size = response.headers.get("Content-Length")
            content_size = content_size + " bytes" if content_size else "N/A"

            message.dispatch("%s (%s, %s)" %
                             (title, content_type, content_size))
        else:
            message.dispatch("No title found for %s" % url)
Ejemplo n.º 15
0
    def twitter(self, message, params=None, **kwargs):
        """Search Twitter (ex: .twitter <query>)"""
        if params:
            query = urllib.urlencode({"q": params, "rpp": 4})
            url = "http://search.twitter.com/search.json?%s" % query
            response = self.irc.fetch_url(url, self.name)
            if not response:
                return

            json_obj = json.loads(response.read())
            results = json_obj["results"]
            if results:
                for r in results:
                    message.dispatch("@%s: %s" %
                                     (r["from_user"],
                                      utils.decode_entities(r["text"].encode(
                                          "ascii", "ignore"))))

            else:
                message.dispatch("No results found: '%s'" % params)
        else:
            message.dispatch(self.twitter.__doc__)
Ejemplo n.º 16
0
Archivo: urls.py Proyecto: roaet/pyhole
    def _find_title(self, message, url):
        """Find the title of a given URL"""
        # NOTE(jk0): Slack does some weird things with URLs.
        url = url.replace("<", "").replace(">", "").split("|")[0]
        if not url.startswith(("http://", "https://")):
            url = "http://" + url

        response = utils.fetch_url(url)
        if response.status_code != 200:
                return

        soup = BeautifulSoup(response.content)
        if soup.head:
            title = utils.decode_entities(soup.head.title.string)
            content_type = response.headers.get("Content-Type").split(";",
                                                                      1)[0]
            content_size = response.headers.get("Content-Length")
            content_size = content_size + " bytes" if content_size else "N/A"

            message.dispatch("%s (%s, %s)" % (title, content_type,
                             content_size))
        else:
            message.dispatch("No title found for %s" % url)
Ejemplo n.º 17
0
    def _find_title(self, message, url):
        """Find the title of a given URL"""
        # NOTE(jk0): Slack does some weird things with URLs.
        url = url.replace("<", "").replace(">", "").split("|")[0]
        if not url.startswith(("http://", "https://")):
            url = "http://" + url

        response = utils.fetch_url(url)
        if response.status_code != 200:
            return

        soup = BeautifulSoup(response.content)
        if soup.head:
            title = utils.decode_entities(soup.head.title.string)
            content_type = response.headers.get("Content-Type").split(";",
                                                                      1)[0]
            content_size = response.headers.get("Content-Length")
            content_size = content_size + " bytes" if content_size else "N/A"

            message.dispatch("%s (%s, %s)" %
                             (title, content_type, content_size))
        else:
            message.dispatch("No title found for %s" % url)
Ejemplo n.º 18
0
 def test_decode_entities(self):
     test_str = "<foo>&#64;&amp;bar&amp;&#64;</foo>"
     self.assertEqual(utils.decode_entities(test_str), "@&bar&@")
Ejemplo n.º 19
0
 def test_decode_entities(self):
     test_str = "<foo>&#64;&amp;bar&amp;&#64;</foo>"
     self.assertEqual(utils.decode_entities(test_str), "@&bar&@")