I
I
I-Cube2019-09-27 15:12:24
Python
I-Cube, 2019-09-27 15:12:24

Python / Telebot - how to send text from a file to a bot?

Hello!
I decided to simplify my life by blocking accounts in the domain.
Sometimes I am out of place, and the accounts are blocked and users cannot normally use the network, printers, etc.
In the scheduler, on EventID #4740, a PowerShell script is launched and writes the names of blocked users to the blocked.txt file.
Then the Python script reads this list and the data is sent by the bot to Telegram, where I analyze it. If there is an urgent need to unlock the account (for example: the CEO or some other bump) , then I send the /unblock command to the bot and the PowerShell script with the unlock is launched.
I can't solve this issue:

import os
import telebot

def read_blocked():
    with open("blocked.txt", "r") as file:
        content = file.read()
        print(content)

bot = telebot.TeleBot('TOKEN')
bot.send_message(chat_id='##', text='ДАННЫЕ ИЗ ФАЙЛА blocked.txt')

How to transfer data from a text editor?
I tried to insert into text = 'read_blocked()', it doesn't work, it stupidly sends the same command.
I know it will be very easy for you, I don't understand Python at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
I-Cube, 2019-09-27
@I-Cube

People, can you tell me how to implement the launch of the script by the handler?
/script and script.cmd is launched on the OS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question