Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .github/workflows/development.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Linting

on:
push:
paths-ignore:
- ".gitignore"
- "README.md"
- "docs/**"

jobs:
build:
uses: unict-dmi/reusable-workflows/.github/workflows/python-lint.yml@main
with:
repo_ref: ${{ github.repository }}
5 changes: 5 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[settings]
profile = black
line_length = 88
multi_line_output = 3
include_trailing_comma = True
14 changes: 10 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ recursive=no

# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
suggestion-mode=yes
; suggestion-mode=yes

# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
Expand Down Expand Up @@ -308,8 +308,8 @@ min-public-methods=2
[EXCEPTIONS]

# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception


[FORMAT]
Expand Down Expand Up @@ -416,7 +416,13 @@ disable=raw-checker-failed,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead
use-symbolic-message-instead,
missing-module-docstring,
missing-function-docstring,
missing-class-docstring,
missing-class-docstring,
too-many-locals


# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Main module"""

import logging

from telegram.ext import Updater

from module.data import config_map
from module.handlers import add_handlers, set_commands
from module.jobs import add_jobs
Expand All @@ -13,7 +16,9 @@ def setup_logging(logs_file: str) -> None:
Args:
logs_file: path to the log file
"""
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
logger = logging.getLogger()

file_handler = logging.FileHandler(f"{logs_file}.log")
Expand All @@ -34,8 +39,8 @@ def main() -> None:

updater = Updater(config_map["token"])
set_commands(updater)
add_handlers(updater.dispatcher)
add_jobs(updater.job_queue)
add_handlers(updater.dispatcher) # type: ignore[has-type]
add_jobs(updater.job_queue) # type: ignore[has-type]

updater.start_polling()
updater.idle()
Expand Down
3 changes: 2 additions & 1 deletion module/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data module"""
from .constants import START_TEXT, CLEAR_LOGFILE_TEXT, DEFAULT_NOTICES_DATA

from .config import config_map
from .constants import CLEAR_LOGFILE_TEXT, DEFAULT_NOTICES_DATA, START_TEXT
from .types import Config, GroupConfig, NoticeData, PageConfig
11 changes: 9 additions & 2 deletions module/data/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Configuration map"""

import os

import yaml

from .types import Config


Expand All @@ -14,7 +17,9 @@ def load_configurations(path: str = "config/") -> Config:
Returns:
dictionary containing the configuration data
"""
with open(os.path.join(path, "settings.yaml"), "r", encoding="utf-8") as main_settings:
with open(
os.path.join(path, "settings.yaml"), "r", encoding="utf-8"
) as main_settings:
new_config = yaml.load(main_settings, Loader=yaml.SafeLoader)

new_config["notices_groups"] = {}
Expand All @@ -25,7 +30,9 @@ def load_configurations(path: str = "config/") -> Config:
group_id = group_file_path.replace(".yaml", "")
full_group_path = os.path.join(notices_groups_path, group_file_path)
with open(full_group_path, "r", encoding="utf-8") as group_file:
new_config["notices_groups"][group_id] = yaml.load(group_file, Loader=yaml.SafeLoader)
new_config["notices_groups"][group_id] = yaml.load(
group_file, Loader=yaml.SafeLoader
)

return new_config

Expand Down
2 changes: 1 addition & 1 deletion module/data/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Constant strings"""
from .types import NoticeData

from .types import NoticeData

START_TEXT = (
"Benvenuto! Questo bot è stato realizzato dagli studenti di Informatica"
Expand Down
1 change: 1 addition & 0 deletions module/data/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Type definitions."""

from typing import TypedDict


Expand Down
16 changes: 9 additions & 7 deletions module/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""Handlers module"""

from telegram import BotCommand
from telegram.ext import (
Updater,
Dispatcher,
CallbackQueryHandler,
CommandHandler,
MessageHandler,
Dispatcher,
Filters,
CallbackQueryHandler,
MessageHandler,
Updater,
)
from .start import start_cmd

from .chat_id import chat_id_cmd
from .clear_logfile import clear_logfile_cmd
from .log import log_msg
from .send_logfile import send_logfile_cmd
from .clear_logfile import clear_logfile_cmd
from .start import start_cmd


def set_commands(updater: Updater) -> None:
Expand All @@ -25,7 +27,7 @@ def set_commands(updater: Updater) -> None:
BotCommand("start", "presentazione iniziale del bot"),
BotCommand("chatid", "ottieni la chat id corrente"),
]
updater.bot.set_my_commands(commands=commands)
updater.bot.set_my_commands(commands=commands) # type: ignore[has-type]


def add_handlers(dp: Dispatcher) -> None:
Expand Down
1 change: 1 addition & 0 deletions module/handlers/chat_id.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""/chatid command"""

from telegram import Update
from telegram.ext import CallbackContext

Expand Down
13 changes: 10 additions & 3 deletions module/handlers/clear_logfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""/clear_logfile command"""

import logging

from telegram import Update
from telegram.ext import CallbackContext
from module.data import config_map, CLEAR_LOGFILE_TEXT

from module.data import CLEAR_LOGFILE_TEXT, config_map


def clear_logfile_cmd(update: Update, context: CallbackContext) -> None:
Expand All @@ -19,6 +22,10 @@ def clear_logfile_cmd(update: Update, context: CallbackContext) -> None:
return

logging.info("Clearing logfile...")
with open("logfile.log", "w", encoding="utf-8"): # overwrite the logfile with an empty file
with open(
"logfile.log", "w", encoding="utf-8"
): # overwrite the logfile with an empty file
pass
context.bot.send_message(chat_id=config_map["log_group_chatid"], text=CLEAR_LOGFILE_TEXT)
context.bot.send_message(
chat_id=config_map["log_group_chatid"], text=CLEAR_LOGFILE_TEXT
)
1 change: 1 addition & 0 deletions module/handlers/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""log handler"""

from telegram import Update
from telegram.ext import CallbackContext

Expand Down
3 changes: 3 additions & 0 deletions module/handlers/send_logfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""/send_logfile command"""

import logging
from datetime import datetime

from telegram import Update
from telegram.ext import CallbackContext

from module.data import config_map


Expand Down
2 changes: 2 additions & 0 deletions module/handlers/start.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""/start command"""

from telegram import Update
from telegram.ext import CallbackContext

from module.data import START_TEXT


Expand Down
11 changes: 9 additions & 2 deletions module/jobs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Jobs module"""

from telegram.ext import JobQueue

from module.data import config_map

from .post_and_clear_log import post_and_clear_log_job
from .update_notices import update_notices_job

Expand All @@ -14,7 +17,11 @@ def add_jobs(job_queue: JobQueue) -> None:
"""
# logfile reset
job_queue.run_repeating(
post_and_clear_log_job, interval=config_map["logfile_reset_interval_minutes"] * 60, first=5
post_and_clear_log_job,
interval=config_map["logfile_reset_interval_minutes"] * 60,
first=5,
)
# update tick
job_queue.run_repeating(update_notices_job, interval=config_map["update_interval"], first=5)
job_queue.run_repeating(
update_notices_job, interval=config_map["update_interval"], first=5
)
13 changes: 10 additions & 3 deletions module/jobs/post_and_clear_log.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Post and clear job"""

import logging
from datetime import datetime

from telegram.ext import CallbackContext
from module.data import config_map, CLEAR_LOGFILE_TEXT

from module.data import CLEAR_LOGFILE_TEXT, config_map


def post_and_clear_log_job(context: CallbackContext) -> None:
Expand All @@ -27,7 +30,11 @@ def post_and_clear_log_job(context: CallbackContext) -> None:

logging.info("Deleting current logfile...")

with open("logfile.log", "w", encoding="utf-8"): # overwrite the logfile with an empty file
with open(
"logfile.log", "w", encoding="utf-8"
): # overwrite the logfile with an empty file
pass

context.bot.sendMessage(chat_id=config_map["log_group_chatid"], text=CLEAR_LOGFILE_TEXT)
context.bot.sendMessage(
chat_id=config_map["log_group_chatid"], text=CLEAR_LOGFILE_TEXT
)
3 changes: 3 additions & 0 deletions module/jobs/update_notices.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Scraping job"""

import logging

from telegram.ext import CallbackContext

from module.data import config_map
from module.scraping import scrape_group

Expand Down
3 changes: 2 additions & 1 deletion module/scraping/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Scraping module"""

from .notice import Notice
from .scraper_links import get_links
from .scraper_group import scrape_group
from .scraper_links import get_links
Loading