Exemplo n.º 1
0
def chuva2(bot, update, chat_id=None):
    if update.message.text == '/chuva2':
        location = 'London'
    else:
        location = update.message.text.split('/chuva2 ')[1]
    if chat_id is None:
        chat_id = update.message.chat_id
    # TODO move this somewhere else
    # Getting results again so we can get the max temperature for the day
    results = get_weather(location)
    max_temp = results['daily']['data'][0]['temperatureMax']
    chove, time_of_rain, chance_of_rain = vai_chover2(location)
    logger.info(f'Chove? {chove}')
    if chove == 'Nao vai chover':
        gif = get_random_giphy(keyword='happy')
    elif chove == 'Pode chover':
        gif = get_random_giphy(keyword='unsure')
    elif chove == 'Provavelmente vai chover':
        gif = get_random_giphy(keyword='probably')
    else:
        gif = get_random_giphy(keyword='sad')
    bot.send_document(chat_id=chat_id,
                      document=gif,
                      caption=f'Bom dia, *{chove}* em {location} hoje '
                      f'*({chance_of_rain}% at {time_of_rain})*.'
                      f'\nMax Temp: *{max_temp}*C',
                      timeout=5000,
                      parse_mode=telegram.ParseMode.MARKDOWN)
Exemplo n.º 2
0
def chuva(bot, update, chat_id=None):
    if update.message.text == '/chuva':
        location = 'London'
    else:
        location = update.message.text.split('/chuva ')[1]
    if chat_id is None:
        chat_id = update.message.chat_id
    # TODO duplicate call for get_weather, need a better way to do it
    # Getting results again so we can get the max temperature for the day
    results = get_weather(location)
    # Check for alerts
    if 'alerts' in results.keys():
        alert = results['alerts'][0]['title']
        alert_time = time.strftime(
            '%l%p', time.localtime(results['alerts'][0]['time']))
        alert_description = results['alerts'][0]['description']
    max_temp = results['daily']['data'][0]['temperatureMax']
    chove, time_of_rain, chance_of_rain = vai_chover(location)
    logger.info(f'Chove? {chove}')
    if chove == 'Vai chover':
        gif = get_random_giphy(keyword='sad')
    else:
        gif = get_random_giphy(keyword='happy')
    bot.send_document(chat_id=chat_id,
                      document=gif,
                      caption=f'Bom dia, *{chove}* em {location} hoje '
                      f'*({chance_of_rain}% at {time_of_rain})*.'
                      f'\nMax Temp: *{max_temp}*C',
                      timeout=5000,
                      parse_mode=telegram.ParseMode.MARKDOWN)
    # Send alert if there is one
    if 'alerts' in results.keys():
        bot.send_document(chat_id=chat_id,
                          document=get_random_giphy('extreme weather'),
                          caption=f'*Incoming Weather Alert for {location}*',
                          timeout=5000,
                          parse_mode=telegram.ParseMode.MARKDOWN)
        bot.send_chat_action(chat_id=chat_id,
                             action=telegram.ChatAction.TYPING)
        time.sleep(5)
        bot.send_message(chat_id=chat_id,
                         text=f'Alerta para {location}:\n'
                         f'{alert} at {alert_time}\n\n'
                         f'{alert_description}',
                         timeout=5000)
Exemplo n.º 3
0
def scheduled_weather(bot, job):
    locations = ['london', 'Maisons-Laffitte', 'Barcelona', 'Geneva']
    for l in locations:
        results = get_weather(l)
        max_temp = results['daily']['data'][0]['temperatureMax']
        chove, time_of_rain, chance_of_rain = vai_chover(l)
        logger.info(f'Chove? {chove}')
        if chove == 'Vai chover':
            gif = get_random_giphy(keyword='sad')
        else:
            gif = get_random_giphy(keyword='happy')
        bot.send_document(
            chat_id=-1001105653255,
            document=gif,
            caption=f'Bom dia!\n'
            f'*{chove}* hoje em {l} *({chance_of_rain}% at {time_of_rain})*.'
            f'\nMax Temp: *{max_temp}*C',
            timeout=5000,
            parse_mode=telegram.ParseMode.MARKDOWN)
Exemplo n.º 4
0
def ping(update, context):
    img = gif.get_random_giphy(keyword='pong')
    context.bot.send_document(chat_id=update.message.chat_id,
                              document=img,
                              timeout=100)
Exemplo n.º 5
0
def ping(bot, update):
    gif = get_random_giphy(keyword='pong')
    bot.send_document(chat_id=update.message.chat_id,
                      document=gif,
                      timeout=100)