Please help me, I can’t figure out the library. I want to pass arguments to the ericsson_alarm function. I don’t understand how to do this
import logging
import ericsson
import configparser
from telegram import Update
from telegram.ext import ContextTypes, CommandHandler, Application
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
def _ericsson():
config = configparser.ConfigParser()
config.read('config.ini')
controllers = {}
for section in config.sections():
if 'MSC' in section:
# Распаковываем словарь в аргументы функции
controllers[section] = ericsson.EricssonTelnet(**dict(config.items(section)))
controllers[section].get_alarms()
return controllers
async def ericsson_alarm(update: Update, context: ContextTypes.DEFAULT_TYPE):
controllers = context.job.context['controllers']
for controller in controllers.values():
alarm = controller.get_alarms()
if alarm:
await context.bot.send_message(chat_id='-ID', text=f"<code>{alarm}</code>")
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
def main() -> None:
application = Application.builder().token('TOKEN').build()
controllers = _ericsson()
# Для отправки сообщений по таймеру
job_queue = application.job_queue
# Команды
start_handler = CommandHandler('start', start)
# Вызываем функции по-таймеру
job_queue.run_repeating(ericsson_alarm, interval=10, first=10, data=controllers)
application.add_handler(start_handler)
application.run_polling()
if __name__ == '__main__':
main()
I tried passing arguments through lambda, it still doesn’t work, it didn’t work through data either
New contributor
Suhoy571 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.