Exemplo n.º 1
0
def lmgtfy(bot, event, *args):
    '''Returns an lmgtfy link from http://lmgtfy.com/ Format is /bot lmgtfy <what to google>'''
    try:
        if args:
            query = ' '.join(args)
            search = quote(query)
            url = 'http://lmgtfy.com/?q=' + search
            msg = _('{}').format(shorten(url))
        else:
            msg = _('{}').format(shorten('http://lmgtfy.com/?q=urbandictionary%20dolphin'))
        yield from bot.coro_send_message(event.conv, msg)
    except BaseException as e:
        msg = _('{} -- {}').format(str(e), event.text)
        yield from bot.coro_send_message(CONTROL, msg)
Exemplo n.º 2
0
def forecast(bot, event, *args):
    if args:
        place = ' '.join(args)
        lookup = pywapi.get_location_ids(place)
        for i in lookup:
            location_id = i
    else:
        location_id = 'USVA0140'
        yield from bot.coro_send_message(event.conv, _("No location given; defaulting to Chantilly, VA"))
    weather_com_result = pywapi.get_weather_from_weather_com(
        location_id, units='imperial')
    place = weather_com_result['location']['name']
    high = weather_com_result['forecasts'][1]['high']
    low = weather_com_result['forecasts'][1]['low']
    day = weather_com_result['forecasts'][1]['day']['text']
    if day == '':
        day = 'N/A'
    night = weather_com_result['forecasts'][1]['night']['text']
    if night == '':
        night = 'N/A'
    date = weather_com_result['forecasts'][1]['date']
    url = links.shorten(
        'http://www.weather.com/weather/today/l/' + location_id)
    msg = _("<b>Forecast for {} on {}:</b><br>Conditions: Day - {}; Night - {}<br>High: {}<br>Low: {}<br>For more information visit {}").format(
        place, date, day, night, high, low, url)
    yield from bot.coro_send_message(event.conv, msg)
Exemplo n.º 3
0
def weather(bot, event, *args):
    '''Gets weather from weather.com. Defaults to Chantilly, VA if no location given. Format is /bot weather <city>,<state/country>'''
    try:
        if args:
            place = ' '.join(args)
            lookup = pywapi.get_location_ids(place)
            for i in lookup:
                location_id = i
        else:
            location_id = 'USVA0140'
            yield from bot.coro_send_message(event.conv, _("No location given; defaulting to Chantilly, VA"))
        weather_com_result = pywapi.get_weather_from_weather_com(
            location_id, units='imperial')
        condition = weather_com_result['current_conditions']['text'].lower()
        temp = weather_com_result['current_conditions']['temperature']
        feelslike = weather_com_result['current_conditions']['feels_like']
        place = weather_com_result['location']['name']
        url = links.shorten(
            'http://www.weather.com/weather/today/l/' + location_id)
        msg = _('<b>Today in {}:</b><br>Temp: {}°F (Feels like: {}°F)<br>Conditions: {}<br>For more information visit {}').format(
            place, temp, feelslike, condition, url)
        yield from bot.coro_send_message(event.conv, msg)
    except BaseException as e:
        msg = _('{} -- {}').format(str(e), event.text)
        yield from bot.coro_send_message(CONTROL, msg)
Exemplo n.º 4
0
def lyrics(bot, event, *args):
    try:
        message = ' '.join(args)
        title = message.split(' by ')[0]
        artist = message.split(' by ')[1]
        g = getlyrics(title, artist)
        msg = _('<b>{} by {}</b><br>{}<br>Full Lyrics: {}').format(
            g['name'], g['artist'], g['lyrics'], shorten(g['url']))
        yield from bot.coro_send_message(event.conv, msg)
    except BaseException as e:
        simple = _('The correct format is /bot lyrics <title> by <artist>')
        msg = _('{} -- {}').format(str(e), event.text)
        yield from bot.coro_send_message(event.conv, simple)
        yield from bot.coro_send_message(CONTROL, msg)