Exemplo n.º 1
0
def format_code(bot, update, **kwargs):
    """Format text as code if it starts with $, ~, \c or \code."""
    code = kwargs.get('groupdict').get('code')
    if code:
        bot.send_message(chat_id=update.message.chat_id,
                         text=monospace(code),
                         parse_mode='markdown')
Exemplo n.º 2
0
def details(bot, update, chat_data):
    answer = update.callback_query.data
    update.callback_query.answer(text='')
    if answer == DETALLE:
        result_steps = chat_data['result_details']
        details = prettify_details(result_steps, chat_data['cant_decimales'])
        update.callback_query.message.reply_text(monospace(details),
                                                 parse_mode='markdown')
    elif answer == OTHER_METHOD:
        chat_data['chosen_method'] = opposite_method[
            chat_data['chosen_method']]
        return calculate(bot, update, chat_data)

    elif answer == EXPORT_CSV:
        csv_results = dump_results_to_csv(
            chat_data['result'],
            chat_data['result_details'],
            chat_data['cant_decimales'],
            chat_data['cota'],
        )
        bot.send_document(
            chat_id=update.callback_query.message.chat_id,
            document=open(csv_results, 'rb'),
        )
    else:
        update.callback_query.message.edit_text(
            '🏳 Mi trabajo aquí ha terminado', reply_markup=None)
        return ConversationHandler.END
Exemplo n.º 3
0
def subte(bot, update):
    """Estado de las lineas de subte, premetro y urquiza."""
    try:
        soup = soupify_url('https://www.metrovias.com.ar')
    except ReadTimeout:
        logger.info('Error in metrovias url request')
        update.message.reply_text('⚠️ Metrovias no responde. Intentá más tarde')
        return

    subtes = soup.find('table', {'class': 'table'})
    REGEX = re.compile(r'Línea *([A-Z]){1} +(.*)', re.IGNORECASE)
    estado_lineas = []
    for tr in subtes.tbody.find_all('tr'):
        estado_linea = tr.text.strip().replace('\n', ' ')
        match = REGEX.search(estado_linea)
        if match:
            linea, estado = match.groups()
            estado_lineas.append((linea, estado))

    bot.send_message(
        chat_id=update.message.chat_id,
        text=monospace(
            '\n'.join(
                format_estado_de_linea(info_de_linea) for info_de_linea in estado_lineas
            )
        ),
        parse_mode='markdown',
    )
Exemplo n.º 4
0
def prettify_table_posiciones(info):
    try:
        return monospace('\n'.join(
            '{:2} | {:12} | {:3} | {:3}'.format(*team_stat)
            for team_stat in info))
    except Exception:
        logger.error(f"Error Prettying info {info}")
        return 'No te entiendo..'
Exemplo n.º 5
0
def pretty_print_dolar(cotizaciones, limit=7):
    """Returns dolar rates separated by newlines and with code markdown syntax.
    ```
    Banco Nacion  | $30.00 | $40.00
    Banco Galicia | $30.00 | $40.00
                   ...
    ```
    """
    return monospace(
        '\n'.join(
            "{:8} | {:7} | {:7}".format(
                normalize(banco, limit), valor['compra'], valor['venta']
            )
            for banco, valor in cotizaciones.items()
        )
    )
Exemplo n.º 6
0
def prettify_food_offers(menu_por_dia, day=None):
    today = datetime.today().weekday()

    if day is None:
        day = MONDAY if today in (SATURDAY, SUNDAY) else today

    try:
        food_offers = menu_por_dia[day]
    except KeyError:
        # If you ask on tuesday at night, only wednesday food will be retrieved.
        logger.info(
            "Menu for today not available. Showing next day's menu. %s",
            menu_por_dia)
        day = next((key for key in sorted(menu_por_dia) if key > day), None)
        food_offers = menu_por_dia.get(day)

    if food_offers:
        header = [f"\t\t\t\t\tMenú del {day_names[day]}"]
        msg = monospace('\n'.join(header + food_offers + ['⚡️ by Yona']))
    else:
        msg = 'No hay información sobre el menú 🍽'

    return msg
Exemplo n.º 7
0
def ingresar_matriz(bot, update):
    update.message.reply_text(
        'Ingresar matriz A. El formato es:\n' + monospace(EXAMPLE_DDOM_ROW),
        parse_mode='markdown',
    )
    return READ_MATRIX_A
Exemplo n.º 8
0
def prettify_rofex(contratos):
    values = '\n'.join(f"{month_name[month]} {year} | {value[:5]}"
                       for month, year, value in contratos)
    header = '  Dólar  | Valor\n'
    return monospace(header +
                     values) if contratos is not None else EMPTY_MESSAGE