Esempio n. 1
0
    def ltc(self):
        url = 'https://btc-e.com/api/2/ltc_usd/ticker'

        request = Browser(url)
        if not request:
            return "Couldn't retrieve LTC data."

        try:
            json = request.json()
        except:
            return "Couldn't parse LTC data."

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
        last = locale.currency(json['ticker']['last'])
        low = locale.currency(json['ticker']['low'])
        high = locale.currency(json['ticker']['high'])

        if self.values:
            try:
                value = locale.currency(float(json['ticker']['last']) * float(self.values[0]))
            except:
                return "Couldn't compute LTC value."

            return 'Value of %s LTC is %s' % (self.values[0], value)
        else:
            return 'Litecoin, Last: %s, Low: %s, High: %s' % (last, low, high)
Esempio n. 2
0
    def g(self):
        if not self.values:
            return "Enter a search"

        key = self.config.google_search_key
        gid = self.config.google_search_id

        params = {'key': key, 'cx': gid, 'fields': 'items(title,link)', 'q': "+".join(self.values)}

        try:
            request = Browser(
                'https://www.googleapis.com/customsearch/v1',
                params=params)

            if request.error:
                return request.error

            json = request.json()

        except Exception as e:
            return "Something's buggered up: %s" % str(e)

        try:
            if len(json["items"]) == 0:
                return "No results"
        except:
            return "Non-standard response: https://www.google.com/#q=%s" % '+'.join(self.values)

        result = json["items"][0]
        title = result["title"]
        link = result["link"]

        return "%s @ %s" % (title, link)
Esempio n. 3
0
    def g(self):
        if not self.values:
            return "Enter a search"

        # If values was a string you don't need the join/etc
        params = {
            'v': '1.0',
            'rsz': 'large',
            'start': '0',
            'q': "+".join(self.values)
        }

        try:
            request = Browser(
                'http://ajax.googleapis.com/ajax/services/search/web',
                params=params)
            json = request.json()
        except:
            return "Something's buggered up"

        if len(json["responseData"]["results"]) == 0:
            return "No results"

        result = json["responseData"]["results"][0]
        title = result["titleNoFormatting"]
        link = result["unescapedUrl"]

        return "%s @ %s" % (title, link)
Esempio n. 4
0
    def get_currency_price(self, name, source, dest='USD', has_gdax=False):
        """
        Retrieve the aggregated last, low and high prices of a crypto currency.
        """
        value_of = None
        if self.values:
            try:
                value_of = int(self.values[0])
            except:
                pass

        url = 'https://www.cryptocompare.com/api/data/coinsnapshot/?fsym=%s&tsym=%s'

        request = Browser(url % (source, dest))
        if not request:
            return "Couldn't retrieve %s data." % source.upper()

        try:
            json = request.json()['Data']['AggregatedData']
        except:
            return "Couldn't parse %s data." % source.upper()

        last = float(json['PRICE'])
        low = float(json['LOW24HOUR'])
        high = float(json['HIGH24HOUR'])
        gdax = None

        if has_gdax:
            gdax = self.get_gdax_price(source, dest, value_of)

        if value_of:
            try:
                value = float(json['PRICE']) * float(value_of)
            except:
                return "Couldn't compute %s value." % source.upper()

            if gdax:
                gdax = ", GDAX: %s" % self.format_currency(gdax)

            return 'Value of %s %s is %s%s' % (value_of, source.upper(), self.format_currency(value), gdax if gdax else '')
        else:
            response = OrderedDict()
            response['Last'] = self.format_currency(last)
            response['Low'] = self.format_currency(low)
            response['High'] = self.format_currency(high)

            if gdax:
                response['GDAX'] = gdax

            prices = ", ".join([": ".join([key, str(val)]) for key, val in response.items()])

            return '%s, %s' % (name, prices)
Esempio n. 5
0
    def giphy(self):

        if not self.values:
            return 'Giphy what?'

        query = '+'.join(self.values)

        try:
            json = Browser('http://api.giphy.com/v1/gifs/random?tag=%s&api_key=dc6zaTOxFJmzC' % query)
            parsed = json.json()
            return parsed['data']['image_original_url']
        except:
            return 'Unable to giphy'
Esempio n. 6
0
    def giphy(self):

        if not self.values:
            return 'Giphy what?'

        query = '+'.join(self.values)

        try:
            json = Browser('http://api.giphy.com/v1/gifs/random?tag=%s&api_key=dc6zaTOxFJmzC' % query)
            parsed = json.json()
            return parsed['data']['image_original_url']
        except:
            return 'Unable to giphy'
Esempio n. 7
0
    def startup(self):
        url = 'http://itsthisforthat.com/api.php?json'
        request = Browser(url)

        if request.error:
            return 'Total fail: %s' % request.error
            sys.exit()

        try:
            json = request.json()
            return 'It\'s a %s for %s' % (json['this'].lower().capitalize(),
                    json['that'].lower().capitalize())
        except Exception as e:
            return 'It\'s a replacement for itsthisforthat.com... (Request failed)'
Esempio n. 8
0
    def startup(self):
        url = 'http://itsthisforthat.com/api.php?json'
        request = Browser(url)

        if request.error:
            return 'Total fail: %s' % request.error
            sys.exit()

        try:
            json = request.json()
            return 'It\'s a %s for %s' % (json['this'].lower().capitalize(),
                    json['that'].lower().capitalize())
        except Exception as e:
            return 'It\'s a replacement for itsthisforthat.com... (Request failed)'
Esempio n. 9
0
    def get_gdax_price(self, source, dest='USD', value_of=None):
        """
        Retrieve the GDAX price of a specific currency.
        """
        gdax = '(No result)'
        gdax_url = 'https://api.gdax.com/products/%s-%s/ticker' % (source.upper(), dest.upper())
        g_request = Browser(gdax_url)
        try:
            g_json = g_request.json()
            gdax = self.format_currency(float(g_json['price']))
            if value_of:
                gdax = float(g_json['price']) * float(value_of)
        except:
            pass

        return gdax
Esempio n. 10
0
    def rhyme(self):
        if not self.values:
            return "Enter a line"

        url = "http://emalmi.kapsi.fi/battlebot/battlebot.fcgi"
        params = "l=en&q=" + '+'.join(self.values)

        request = Browser('%s?%s' % (url, params))

        try:
            json = request.json()
            rhyme = choice(json["rhymes"])
            return rhyme['line']
        except Exception as e:
            self.chat('...')
            self._act("drops mic in shame.")
            return
Esempio n. 11
0
    def rhyme(self):
        if not self.values:
            return "Enter a line"

        url = "http://emalmi.kapsi.fi/battlebot/battlebot.fcgi"
        params = "l=en&q=" + '+'.join(self.values)

        request = Browser('%s?%s' % (url, params))

        try:
            json = request.json()
            rhyme = choice(json["rhymes"])
            return rhyme['line']
        except Exception as e:
            self.chat('...')
            self._act("drops mic in shame.")
            return
Esempio n. 12
0
    def anagram(self):
        if not self.values:
            return "Enter a word or phrase"

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

        request = Browser(url)
        if not request:
            return 'Error'

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


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

        request = Browser(url)
        if not request:
            return 'Error'

        try:
            json = request.json()
            return json['best']
        except Exception as e:
            self.chat("Couldn't parse.", str(e))
            return
Esempio n. 14
0
    def weather(self):

        if not self.values:
            return "Please enter a zip/location"

        if not self.secrets.weather_api:
            return "wunderground api key is not set"

        if not self.values:
            params = "autoip.json?geo_ip=%s" % self.lastip
        else:
            params = "%s.json" % self.values[0]

        base = "http://api.wunderground.com/api/%s/conditions/q/" % self.secrets.weather_api

        url = base + params

        try:
            request = Browser(url)
        except:
            return "Couldn't get weather."

        if not request:
            return "Couldn't get weather."

        try:
            json = request.json()
            json = json['current_observation']
        except:
            return "Couldn't parse weather."

        location = json['display_location']['full']
        condition = json['weather']
        temp = json['temperature_string']
        humid = json['relative_humidity']
        wind = json['wind_string']
        feels = json['feelslike_string']
        hourly = 'http://www.weather.com/weather/hourbyhour/l/%s' % self.values[
            0]
        radar = shorten('http://www.weather.com/weather/map/interactive/l/%s' %
                        self.values[0])

        base = "%s, %s, %s, Humidity: %s, Wind: %s, Feels like: %s, Radar: %s"
        return base % (location, condition, temp, humid, wind, feels, radar)
Esempio n. 15
0
    def weather(self):

        if not self.values:
            return "Please enter a zip/location"

        if not self.secrets.weather_api:
            return "wunderground api key is not set"

        if not self.values:
            params = "autoip.json?geo_ip=%s" % self.lastip
        else:
            params = "%s.json" % self.values[0]

        base = "http://api.wunderground.com/api/%s/conditions/q/" % self.secrets.weather_api

        url = base + params

        try:
            request = Browser(url)
        except:
            return "Couldn't get weather."

        if not request:
            return "Couldn't get weather."

        try:
            json = request.json()
            json = json['current_observation']
        except:
            return "Couldn't parse weather."

        location = json['display_location']['full']
        condition = json['weather']
        temp = json['temperature_string']
        humid = json['relative_humidity']
        wind = json['wind_string']
        feels = json['feelslike_string']
        hourly = 'http://www.weather.com/weather/hourbyhour/l/%s' % self.values[0]
        radar = shorten('http://www.weather.com/weather/map/interactive/l/%s' % self.values[0])

        base = "%s, %s, %s, Humidity: %s, Wind: %s, Feels like: %s, Radar: %s"
        return base % (location, condition, temp, humid, wind, feels, radar)
Esempio n. 16
0
    def g(self):
        if not self.values:
            return "Enter a search"

        # If values was a string you don't need the join/etc
        params = {'v': '1.0', 'rsz': 'large', 'start': '0',
                  'q': "+".join(self.values)}

        try:
            request = Browser(
                'http://ajax.googleapis.com/ajax/services/search/web',
                params=params)
            json = request.json()
        except:
            return "Something's buggered up"

        if len(json["responseData"]["results"]) == 0:
            return "No results"

        result = json["responseData"]["results"][0]
        title = result["titleNoFormatting"]
        link = result["unescapedUrl"]

        return "%s @ %s" % (title, link)
Esempio n. 17
0
    def doge(self):
        url = 'http://dogecoinaverage.com/USD.json'

        request = Browser(url)
        if not request:
            return "Couldn't retrieve DOGE data."

        try:
            json = request.json()
        except:
            return "Couldn't parse DOGE data."

        weighted = float(json['vwap'])

        if self.values:
            try:
                locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
                value = locale.currency(weighted * float(self.values[0]))
            except:
                return "Couldn't compute DOGE value."

            return 'Value of %s DOGE is %s' % (self.values[0], value)
        else:
            return 'Dogecoin, Volume-Weighted Average Price: $%s' % (weighted)