Created
January 31, 2020 05:53
-
-
Save Poolitzer/81051f87b614d5cd5f1953ab89e1d8cf to your computer and use it in GitHub Desktop.
Ever wanted to download something and send it via telegram without having to save it to a file? Fear not!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
def downloader(bot, url, timeout=None): | |
# if you receive a timeout error, pass an increasing timeout until you don't | |
buf = bot.request.retrieve(url, timeout=timeout) | |
# turning the byte stream into a file_like object without actually writing it to a file | |
file_like = io.BytesIO(buf) | |
# and returning it | |
return file_like |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment