So I am writing telegram bot, which is really my first serious project on Python.
When user sends video or audio, my bot should modify it in some way, which is same for both. So I have my algorithm, but it needs to know file size of whatever user sent to it.
Here’s the problem. Telegram gives me file size in message.audio.file_size or message.video.file_size accordingly, not in some message.file.file_size.
(I also can get content type by message.content_type)
First thing that came into my mind was to do something like f’message.{message.content_type}.file_size’, but that would give me a str, not variable content.
Here’s how it is done now:
if message.content_type == 'audio':
if message.audio.file_size > 1000000000:
...
elif message.content_type == 'video':
if message.video.file_size > 1000000000:
...
I feel like it can be done shorter and simpler.
heavennborn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.