Esempio n. 1
0
def news_command(bot, update, args):
    """Defining the `news` command"""

    if len(args) and int(args[0]) <= 10:
        news_array = utils.read_json("json/news.json")[0:int(args[0])]
    else:
        news_array = utils.read_json("json/news.json")

    news_to_string = ""
    for i, item in enumerate(news_array):
        item["suffix"] = '...' if len(item['description']) > 75 else ''
        news_to_string += str(i+1)+"- [{title}]({link})\n{description:.75}{suffix}\n".format(**item)

    bot.sendMessage(update.message.chat_id, parse_mode='Markdown', text=news_to_string)
Esempio n. 2
0
def news_command(bot, update, args):
    """Defining the `news` command"""

    if len(args) and int(args[0]) <= 10:
        news_array = utils.read_json("json/news.json")[0:int(args[0])]
    else:
        news_array = utils.read_json("json/news.json")

    news_to_string = ""
    for i, news in enumerate(news_array):
        truncated_descr = news['description'][:75] + '...' if len(news['description']) > 75 \
                          else news['description']
        news_to_string += str(i+1) + "- [" + news['title'] + "](" + news['link'] + ")\n" \
                          + truncated_descr + "\n"

    bot.sendMessage(update.message.chat_id, parse_mode='Markdown', text=news_to_string)
Esempio n. 3
0
def student_office_command(bot, update):
    """Defining the `student_office` command"""

    data = utils.read_json("json/student_office.json")
    student_office_info = "Orari: " + data['orari'] + \
                          "\nIndirizzo: " + data['indirizzo'] + \
                          "\nTelefono: " + data['telefono'] + \
                          "\nE-mail: " + data['e-mail']

    bot.sendMessage(update.message.chat_id, text=student_office_info)
Esempio n. 4
0
def prof_command(bot, update, args=None):
    """Defining the `prof` command"""

    data = utils.read_json("json/professors.json")
    prof_name = args[0].strip().lower() if args else ''
    if prof_name:
        fmt = '{nome} - {telefono} - {e-mail} - {corsi}\n'
    else:
        fmt = '{nome} - {telefono} - {e-mail}'
    professors = '\n'.join(fmt.format(**prof) for prof in data
                           if prof_name in prof['nome'].lower())

    bot.sendMessage(update.message.chat_id, text=professors + '\n')
Esempio n. 5
0
def check_news():
    """This function check if there are some unread news from the website"""

    pulled_news = pull_news(5)
    stored_news = utils.read_json("json/news.json")
    unread_news = []

    if len(pulled_news) > 0:
        for single_pulled in pulled_news:
            counter = 0
            for single_stored in stored_news:
                if len(single_pulled) > 0:
                    if single_pulled == single_stored:
                        counter = counter+1

            if counter == 0:
                unread_news.append({"title": single_pulled["title"],
                                    "description": single_pulled['description'],
                                    "link": single_pulled['link']})

    return unread_news
Esempio n. 6
0
def prof_command(bot, update, args):
    """Defining the `prof` command"""

    data = utils.read_json("json/professors.json")
    professors = ""

    if len(args):
        for prof in data:
            if args[0].lower() in prof['nome'].lower():
                professors += prof['nome'] + \
                              " - " + prof['telefono'] + \
                              " - " + prof['e-mail'] + \
                              " - " + prof['corsi'] + \
                              "\n\n"
    else:
        for prof in data:
            professors += prof['nome'] + \
                          " - " + prof['telefono'] + \
                          " - " + prof['e-mail'] + \
                          "\n"

    bot.sendMessage(update.message.chat_id, text=professors)
Esempio n. 7
0
def adsu_command(bot, update):
    """Defining the `canteen` command"""

    data = utils.read_json("json/adsu.json")
    bot.sendMessage(update.message.chat_id, text=data['info'])
Esempio n. 8
0
def canteen_command(bot, update):
    """Defining the `canteen` command"""

    data = utils.read_json("json/mensa.json")
    bot.sendMessage(update.message.chat_id, text="Orari: " + data['orari'])
Esempio n. 9
0
def adsu_command(bot, update):
    """Defining the `adsu` command"""

    adsu_info = utils.read_json("json/adsu.json")['info']
    bot.sendMessage(update.message.chat_id, text=adsu_info)
Esempio n. 10
0
def canteen_command(bot, update):
    """Defining the `canteen` command"""

    canteen_info = 'Orari: {orari}'.format(**utils.read_json("json/mensa.json"))
    bot.sendMessage(update.message.chat_id, text=canteen_info)
Esempio n. 11
0
def student_office_command(bot, update):
    """Defining the `student_office` command"""

    fmt = 'Orari: {orari}\nIndirizzo: {indirizzo}\nTelefono: {telefono}\nE-mail: {e-mail}'
    student_office_info = fmt.format(**utils.read_json("json/student_office.json"))
    bot.sendMessage(update.message.chat_id, text=student_office_info)