Exemplo n.º 1
0
async def test_rappresentanti_cmd(client: TelegramClient):
    """Tests the rappresentanti command

    Args:
        client (TelegramClient): client used to simulate the user
    """
    conv: Conversation
    async with client.conversation(bot_tag, timeout=TIMEOUT) as conv:
        await conv.send_message("/rappresentanti")  # send a command
        resp: Message = await conv.get_response()
        print(read_md("rappresentanti"))
        print(get_telegram_md(resp.text))
        assert read_md("rappresentanti") == get_telegram_md(resp.text)
Exemplo n.º 2
0
def updater_schedule(context):
    session = dryscrape.Session()
    aulario_url = read_md("aulario")
    session.visit(aulario_url)
    time.sleep(0.5)

    response = session.body()

    tables = pd.read_html(response)
    days = {}
    for k, table in enumerate(tables):
        rooms = table.iloc[:, 0]
        schedule = table.iloc[:, 1:]
        subjects = {}
        for c in schedule:
            for i, row in enumerate(table[c]):
                if not pd.isnull(row):
                    r = row[:20] + rooms[i]
                    if not r in subjects:
                        subjects[r] = {}

                        subjects[r]["subj"] = row.replace('[]', '').replace(
                            '[', '(').replace(']', ')')
                        subjects[r]["times"] = []
                        subjects[r]['room'] = rooms[i]
                    if c[-1] == "1":
                        c = c[:3] + "30"
                    subjects[r]['times'].append(c)
        days[k] = subjects

    with open("data/json/subjs.json", "w+") as outfile:
        json.dump(days, outfile)
Exemplo n.º 3
0
def informative_callback(update: Update, context: CallbackContext):
    cmd = update.message.text.split(' ')[0][
        1:]  #prende solo la prima parola del messaggio (cioè il comando) escludendo lo slash
    check_log(update, context, cmd)
    message_text = read_md(cmd)
    context.bot.sendMessage(chat_id=update.message.chat_id,
                            text=message_text,
                            parse_mode='Markdown')
Exemplo n.º 4
0
def md_handler(update: Update, context: CallbackContext):
    query = update.callback_query

    data = query.data.replace("md_", "")

    message_text = read_md(data)
    check_log(update, context, data, 1)

    context.bot.editMessageText(text=message_text,
                                chat_id=query.message.chat_id,
                                message_id=query.message.message_id,
                                parse_mode='Markdown')
Exemplo n.º 5
0
def start(update: Update, context: CallbackContext):
    """Called by the /start command.
    Sends a welcome message

    Args:
        update: update event
        context: context passed by the handler
    """
    reply_keyboard = get_help_keyboard()
    message_text = read_md("start")
    context.bot.sendMessage(chat_id=update.message.chat_id,
                            text=message_text,
                            reply_markup=reply_keyboard)
Exemplo n.º 6
0
def informative_callback(update: Update, context: CallbackContext):
    # controllo per poter gestire i comandi (/comando) e i messaggi inviati premendo i bottoni (❔ Help)
    if update.message.text[0] == '/':
        cmd = update.message.text.split(' ')[0][
            1:]  #prende solo la prima parola del messaggio (cioè il comando) escludendo lo slash
    else:
        cmd = update.message.text.split(
            ' ')[1].lower()  # prende la prima parola dopo l'emoji
    check_log(update, context, cmd)
    message_text = read_md(cmd)
    context.bot.sendMessage(chat_id=update.message.chat_id,
                            text=message_text,
                            parse_mode='Markdown')
Exemplo n.º 7
0
def md_handler(update: Update, context: CallbackContext):
    query = update.callback_query

    data = query.data.replace("md_", "")
    message_text = read_md(data)

    if data == "help":
        message_text = message_text.replace("<cusicon>",
                                            CUSicon[random.randint(0, 5)])

    check_log(update, context, data, 1)

    context.bot.editMessageText(text=message_text,
                                chat_id=query.message.chat_id,
                                message_id=query.message.message_id,
                                parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 8
0
async def test_help_cmd(client: TelegramClient):
    """Tests the rappresentanti command

    Args:
        client (TelegramClient): client used to simulate the user
    """
    conv: Conversation
    async with client.conversation(bot_tag, timeout=TIMEOUT) as conv:
        await conv.send_message("/help")  # send a command
        resp: Message = await conv.get_response()

        assert "@DMI_Bot risponde ai seguenti comandi:" == resp.text

        await resp.click(text="📖 Esami (link)"
                         )  # click "📖 Esami (link)" inline button
        resp: Message = await conv.get_edit()

        assert read_md("esami_link") == get_telegram_md(resp.text)
Exemplo n.º 9
0
def informative_callback(update: Update, context: CallbackContext):
    """Called by any command that needs to show information to the user

    Args:
        update: update event
        context: context passed by the handler
    """
    # controllo per poter gestire i comandi (/comando) e i messaggi inviati premendo i bottoni (❔ Help)
    if update.message.text[0] == '/':
        cmd = update.message.text.split(' ')[0][
            1:]  #prende solo la prima parola del messaggio (cioè il comando) escludendo lo slash
    else:
        cmd = update.message.text.split(
            ' ')[1].lower()  # prende la prima parola dopo l'emoji
    check_log(update, cmd)
    message_text = read_md(cmd)
    context.bot.sendMessage(chat_id=update.message.chat_id,
                            text=message_text,
                            parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 10
0
def md_handler(update: Update, context: CallbackContext):
    """Called by any query that needs to show the contents of a markdown file to the user

    Args:
        update: update event
        context: context passed by the handler
    """
    query = update.callback_query

    data = query.data.replace("md_", "")
    message_text = read_md(data)

    if data == "help":
        message_text = message_text.replace("<cusicon>",
                                            CUSicon[random.randint(0, 5)])

    check_log(update, data, is_query=True)

    context.bot.editMessageText(text=message_text,
                                chat_id=query.message.chat_id,
                                message_id=query.message.message_id,
                                parse_mode=ParseMode.MARKDOWN)
Exemplo n.º 11
0
    def scrape(cls, delete: bool = False):
        """Scrapes the timetable slots of the provided year and stores them in the database

        Args:
            delete: whether the table contents should be deleted first. Defaults to False.
        """
        timetable_slots = []
        response = requests.get(read_md("aulario")).text
        tables = pd.read_html(response)

        for k, table in enumerate(tables):
            rooms = table.iloc[:, 0]
            schedule = table.iloc[:, 1:]
            subjects = {}
            for time in schedule:
                for i, row in enumerate(table[time]):
                    if time[-1] == "1":
                        time = time[:3] + "30"
                    if not pd.isnull(row):
                        r = row[:20] + rooms[i]
                        if not r in subjects:
                            subjects[r] = cls(nome=row.replace('[]', '').replace('[', '(').replace(']', ')'),
                                              giorno=k,
                                              ora_inizio=time,
                                              ora_fine=time,
                                              aula=rooms[i])
                        else:
                            subjects[r].ora_fine = time
            timetable_slots.extend(subjects.values())

        if delete:
            cls.delete_all()

        offset = DbManager.count_from(table_name=cls().table)  # number of rows already present
        for i, timetable_slot in enumerate(timetable_slots):
            timetable_slot.ID = i + offset  # generate the ID of the timetable slot based on its position in the array
        cls.bulk_save(timetable_slots)
        logger.info("Aulario loaded.")
Exemplo n.º 12
0
def start(update: Update, context: CallbackContext):
    reply_keyboard = get_help_keyboard()
    message_text = read_md("start")
    context.bot.sendMessage(chat_id=update.message.chat_id,
                            text=message_text,
                            reply_markup=reply_keyboard)
Exemplo n.º 13
0
def informative_callback(update: Update, context: CallbackContext, cmd):
    check_log(update, context, cmd)
    message_text = read_md(cmd)
    context.bot.sendMessage(chat_id=update.message.chat_id,
                            text=message_text,
                            parse_mode='Markdown')