I am scraping new images received in a Telegram channel using Telethon. My code works ok (it scrapes messages and download files using the preset naming convention) but I cannot seem to set my own filename for the downloaded images. When I add the file_name argument I get an error.
The docs suggest it is possible to set a name for downloaded media but I get the error below.
Code that causes the issue
import configparser
import json
import re
from telethon.errors import SessionPasswordNeededError
from telethon import TelegramClient, events, sync
from telethon.tl.functions.messages import (GetHistoryRequest)
from telethon.tl.types import (
PeerChannel
)
...
@client.on(events.NewMessage(chats=chat_id))
async def newMessageListener(event):
new_message = event.message.message
print(new_message)
print()
file_name = "new_image.jpg"
if event.message.photo:
await event.download_media(new_message, file_name)
print("New image received")
with client:
client.run_until_disconnected()
Traceback
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\telethon\client\updates.py", line 454, in _dispatch_update
await callback(event)
File "C:/Users/PycharmProjects/TamTelegram/ps_Scrapev1.py", line 27, in newMessageListener
await event.download_media(new_message, file_name)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\telethon\tl\custom\message.py", line 837, in download_media
return await self._client.download_media(self, *args, **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\telethon\sync.py", line 34, in syncified
coro = method(*args, **kwargs)
TypeError: download_media() takes from 2 to 3 positional arguments but 4 were given
I am scraping new images received in a Telegram channel using Telethon. My code works ok (it scrapes messages and download files using the preset naming convention) but I cannot seem to set my own filename for the downloaded images. When I add the file_name argument I get an error.
The docs suggest it is possible to set a name for downloaded media but I get the error below.
Code that causes the issue
Traceback