예제 #1
0
파일: datafiles.py 프로젝트: lity99/uguubot
def slogan(inp):
    """slogan <word> -- Makes a slogan for <word>."""
    out = random.choice(slogans)
    if inp.lower() and out.startswith("<text>"):
        inp = text.capitalize_first(inp)

    return out.replace('<text>', inp)
예제 #2
0
def slogan(inp):
    "slogan <word> -- Makes a slogan for <word>."
    out = random.choice(slogans)
    if inp.lower() and out.startswith("<text>"):
        inp = text.capitalize_first(inp)

    return out.replace('<text>', inp)
예제 #3
0
파일: woot.py 프로젝트: Cameri/Gary
def get_woots(inp):
    woots = {}
    for k, v in inp.items():
        try:
            w = {}
            soup = http.get_soup(api + v)

            w['product'] = soup.find('woot:product').text
            w['wootoff'] = soup.find('woot:wootoff').text
            w['price'] = soup.find('woot:price').text
            w['pricerange'] = soup.find('woot:pricerange').text
            w['shipping'] = soup.find('woot:shipping').text
            w['url'] = "http://{}".format(v)
            w['soldout'] = soup.find('woot:soldout').text
            w['soldoutpercent'] =  soup.find('woot:soldoutpercentage').text

            category = text.capitalize_first(k if k == 'woot' else "%s woot" % k)
            if w['wootoff'] != "false":
                category += "off!"

            woots[category] = w
        except:
            continue

    return woots
예제 #4
0
def time_command(inp, bot=None):
    """time <area> -- Gets the time in <area>"""

    query = "current time in {}".format(inp)

    api_key = bot.config.get("api_keys", {}).get("wolframalpha", None)
    if not api_key:
        return "error: no wolfram alpha api key set"

    request = http.get_xml(api_url, input=query, appid=api_key)
    current_time = " ".join(
        request.xpath("//pod[@title='Result']/subpod/plaintext/text()"))
    current_time = current_time.replace("  |  ", ", ")

    if current_time:
        # nice place name for UNIX time
        if inp.lower() == "unix":
            place = "Unix Epoch"
        else:
            place = capitalize_first(" ".join(
                request.xpath(
                    "//pod[@"
                    "title='Input interpretation']/subpod/plaintext/text()"))
                                     [16:])
        return "{} - \x02{}\x02".format(current_time, place)
    else:
        return "Could not get the time for '{}'.".format(inp)
예제 #5
0
파일: rdio.py 프로젝트: Cameri/Gary
def rdio(inp, api_key=None, bot=None):
    """.rdio [-track|-artist|-album] <search term> - Search for specified or any media via Rdio."""
    if not isinstance(api_key, dict) or any(key not in api_key for key in
            ('consumer', 'consumer_secret')):
        return "error: No api key set"
    else:
        api_secret, api_key = api_key.values()

    inp = inp.split(' ')
    if len(inp) > 1 and inp[0] in ['-track', '-artist', '-album']:
            kind = text.capitalize_first(inp.pop(0)[1:])
            query = " ".join(inp)
    else:
        kind, query = "Track,Album,Artist", " ".join(inp)

    data = getdata(query, kind, api_key, api_secret)
    try:
        info = data['result']['results'][0]
    except IndexError:
        return "No results."

    return formatdata(info)
예제 #6
0
파일: time.py 프로젝트: edwinfinch/uguubot
def watime(inp, bot=None):
    """time <area> -- Gets the time in <area>"""

    query = "current time in {}".format(inp)

    api_key = bot.config.get("api_keys", {}).get("wolframalpha", None)
    if not api_key:
        return "error: no wolfram alpha api key set"

    request = http.get_xml(api_url, input=query, appid=api_key)
    time = " ".join(request.xpath("//pod[@title='Result']/subpod/plaintext/text()"))
    time = time.replace("  |  ", ", ")

    if time:
        # nice place name for UNIX time
        if inp.lower() == "unix":
            place = "Unix Epoch"
        else:
            place = capitalize_first(" ".join(request.xpath("//pod[@"
                                                            "title='Input interpretation']/subpod/plaintext/text()"))[
                                     16:])
        return "{} - \x02{}\x02".format(time, place)
    else:
        return u"Could not get the time for '{}'.".format(inp)
예제 #7
0
def config_list(name, config):
    section = config[name]
    return "{}: {}".format(text.capitalize_first(name), ", ".join(section))
예제 #8
0
파일: slogan.py 프로젝트: Cameri/Gary
def sloganspam(inp, say=''):
    for x in range(0, 5):
        out = random.choice(slogans)
        if inp.lower() and out.startswith("<text>"):
            inp = text.capitalize_first(inp)
        say(out.replace('<text>', inp))