There are ≈ 2.5k archives of different size from 20kb to 2gb. They need to upload to telegram channel (not with links to other storages, clouds, etc.) Thought that it could be done through a bot (then I did not know about the 50mb limit).
Wrote the following code:
@dp.message_handler(commands=['send_files'])
async def send_files_handler(message: types.Message):
files = os.listdir(DIRECTORY)
for files in files:
with open(os.path.join(DIRECTORY, file), 'rb') as f:
try:
# await bot.send_document(chat_id=CHAT_ID, document=f)
await bot.send_document('CHENAL_ID', document=f)`
I write the command /send_files
in the bot's PM, the bot starts sending all the files from the specified directory.
I tried to run it, I saw after loading a few files errors. I wrote a sending block in try:
and added a function to write in txt paths to files that failed to send
try:
await bot.send_document('CHENAL_ID', document=f)
except:
r_f = open(r'D:\test\erorr.txt','a')
r_f.write(str(f)+'\n')
f.close()`
Wrote a script to move the files from erorr.txt
to a separate folder to see what's wrong with them later.
I realized that for some reason there were files up to 50mb and they are not in the channel. Repeated the algorithm again, but in a new directory and with a new file erorr.txt
. Again, some of the files were downloaded and some were not. And I did it again many, many times.
I've seen article on habr where they use "User-bot", he sends files to the bot, and it in turn sends the file to the desired chat.
In general, I need a working method for auto uploading files to tg channel up to 2gb.