Esempio n. 1
0
    def random(self):
        default = [0, 9999, 1, 1]

        if self.values and self.values[0][:1] == 'd':
            default[0] = 1
            default[1] = self.values[0][1:]
            send = default
        elif 'd' in self.values[0]:
            default[0] = 1
            num, high = self.values[0].split('d')
            default[1] = high
            default[3] = num
            send = default
        elif self.values:
            splice = len(self.values)
            send = self.values + default[splice:]
        else:
            send = default

        low, high, sets, nums = send
            
        base = 'http://qrng.anu.edu.au/form_handler.php?repeats=no&'            
        params = "min_num=%s&max_num=%s&numofsets=%s&num_per_set=%s" % (low, high, sets, nums)

        url = base + params

        # Needs to be vastly improved for other sets
        site = Browse(url)
        result = site.read().split(':')[2].strip()[:-6]

        return result
Esempio n. 2
0
    def random(self):
        default = [0, 9999, 1, 1]

        if self.values and self.values[0][:1] == 'd':
            default[0] = 1
            default[1] = self.values[0][1:]
            send = default
        elif 'd' in self.values[0]:
            default[0] = 1
            num, high = self.values[0].split('d')
            default[1] = high
            default[3] = num
            send = default
        elif self.values:
            splice = len(self.values)
            send = self.values + default[splice:]
        else:
            send = default

        low, high, sets, nums = send

        base = 'http://qrng.anu.edu.au/form_handler.php?repeats=no&'
        params = "min_num=%s&max_num=%s&numofsets=%s&num_per_set=%s" % (
            low, high, sets, nums)

        url = base + params

        # Needs to be vastly improved for other sets
        site = Browse(url)
        result = site.read().split(':')[2].strip()[:-6]

        return result
Esempio n. 3
0
    def ety(self):
        if not self.values:
            self.chat("Enter a word")
            return

        word = self.values[0]
        params = {
            'allowed_in_frame': '0',
            'searchmode': 'term',
            'search': word
        }

        site = Browse("http://www.etymonline.com/index.php", params)
        if site.error:
            self.chat(site.error)
            return

        cont = bs4(site.read())

        heads = cont.findAll("dt")
        defs = cont.findAll("dd")

        if not len(defs):
            self.chat("Couldn't find anything")
            return

        try:
            ord = int(self.values[1])
        except:
            ord = 1

        if ord > len(defs):
            ord = 1

        ord -= 1
        if ord < 0:
            ord = 0

        try:
            _word = ''.join(heads[ord].findAll(text=True))
            _def = ''.join(defs[ord].findAll(text=True))
        except Exception as e:
            self.chat('Failed to parse.', error=e)
            return

        return "Etymology %s of %s for %s: %s" % (str(ord + 1), str(
            len(defs)), _word, _def)
Esempio n. 4
0
    def anagram(self):
        if not self.values:
            self.chat("Enter a word or phrase")
            return

        word = ''.join(self.values)
        url = 'http://www.anagramica.com/best/%s' % word

        site = Browse(url)
        if site.error:
            self.chat(site.error)
            return

        try:
            json = simplejson.loads(site.read())
            return json['best']
        except Exception as e:
            self.chat("Couldn't parse.", str(e))
Esempio n. 5
0
    def anagram(self):
        if not self.values:
            self.chat("Enter a word or phrase")
            return

        word = ''.join(self.values)
        url = 'http://www.anagramica.com/best/%s' % word

        site = Browse(url)
        if site.error:
            self.chat(site.error)
            return

        try:
            json = simplejson.loads(site.read())
            return json['best']
        except Exception as e:
            self.chat("Couldn't parse.", str(e))
Esempio n. 6
0
    def ety(self):
        if not self.values:
            self.chat("Enter a word")
            return

        word = self.values[0]
        params = {'allowed_in_frame': '0', 'searchmode': 'term', 'search': word}

        site = Browse("http://www.etymonline.com/index.php", params)
        if site.error:
            self.chat(site.error)
            return

        cont = bs4(site.read())

        heads = cont.findAll("dt")
        defs = cont.findAll("dd")

        if not len(defs):
            self.chat("Couldn't find anything")
            return

        try:
            ord = int(self.values[1])
        except:
            ord = 1

        if ord > len(defs):
            ord = 1

        ord -= 1
        if ord < 0:
            ord = 0

        try:
            _word = ''.join(heads[ord].findAll(text=True))
            _def = ''.join(defs[ord].findAll(text=True))
        except Exception as e:
            self.chat('Failed to parse.', error=e)
            return

        return "Etymology %s of %s for %s: %s" % (str(ord + 1), str(len(defs)), _word, _def)
Esempio n. 7
0
    def linker(self, urls):
        for url in urls:
            # Special behaviour for Twitter URLs
            match_twitter_urls = re.compile('http[s]?://(www.)?twitter.com/.+/status/([0-9]+)')

            twitter_urls = match_twitter_urls.findall(url)
            if len(twitter_urls):
                self.tweet(twitter_urls)
                return

            if url.find('gist.github') != -1:
                return

            if randint(1, 5) == 1:
                try:
                    self.commands.get('tweet', self.default)(url)
                except:
                    pass

            fubs = 0
            title = "Couldn't get title"

            site = Browse(url)

            if site.error:
                self.chat('Total fail: %s' % site.error)
                continue

            roasted = shorten(url)
            if not roasted:
                roasted = "Couldn't roast"
                fubs += 1

            try:
                ext = site.headers()['content-type'].split('/')[1]
            except:
                ext = False

            images = [
                'gif',
                'png',
                'jpg',
                'jpeg',
            ]

            if ext in images:
                title = 'Image'
                # Switch this to a Browse method
                if STORE_IMGS:
                    fname = url.split('/').pop()
                    path = IMGS + fname
                    self.butler.do(savefromweb, (url, path, self.lastsender), 'Thumb @ %s')

            elif ext == 'pdf':
                title = 'PDF Document'

            else:
                title = site.title()

            # If you have a delicious account set up. Yes, delicious
            # still exists. Could be updated to a cooler link
            # collecting service.
            if STORE_URLS:
                postdelicious(url, title, self.lastsender)

            if fubs == 2:
                self.chat("Total fail")
            else:
                self.chat("%s @ %s" % (unescape(title), roasted))
Esempio n. 8
0
    def linker(self, urls):
        for url in urls:
            # Special behaviour for Twitter URLs
            match_twitter_urls = re.compile(
                'http[s]?://(www.)?twitter.com/.+/status/([0-9]+)')

            twitter_urls = match_twitter_urls.findall(url)
            if len(twitter_urls):
                self.tweet(twitter_urls)
                return

            if url.find('gist.github') != -1:
                return

            if randint(1, 5) == 1:
                try:
                    self.commands.get('tweet', self.default)(url)
                except:
                    pass

            fubs = 0
            title = "Couldn't get title"

            site = Browse(url)

            if site.error:
                self.chat('Total fail: %s' % site.error)
                continue

            roasted = shorten(url)
            if not roasted:
                roasted = "Couldn't roast"
                fubs += 1

            try:
                ext = site.headers()['content-type'].split('/')[1]
            except:
                ext = False

            images = [
                'gif',
                'png',
                'jpg',
                'jpeg',
            ]

            if ext in images:
                title = 'Image'
                # Switch this to a Browse method
                if STORE_IMGS:
                    fname = url.split('/').pop()
                    path = IMGS + fname
                    self.butler.do(savefromweb, (url, path, self.lastsender),
                                   'Thumb @ %s')

            elif ext == 'pdf':
                title = 'PDF Document'

            else:
                title = site.title()

            # If you have a delicious account set up. Yes, delicious
            # still exists. Could be updated to a cooler link
            # collecting service.
            if STORE_URLS:
                postdelicious(url, title, self.lastsender)

            if fubs == 2:
                self.chat("Total fail")
            else:
                self.chat("%s @ %s" % (unescape(title), roasted))