-
-
Save muhammedfurkan/7db29b67410c55c8d069816cb71aca40 to your computer and use it in GitHub Desktop.
split a long text into small chunks, it won't cut your words.
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
def split_message(text, length=4096, offset=200): | |
return [text[text.find('\n', i - offset, i + 1) if text.find('\n', i - offset, i + 1) != -1 else i: | |
text.find('\n', i + length - offset, i + length) if text.find('\n', i + length - offset, | |
i + length) != -1 else i + length] for | |
i | |
in | |
range(0, len(text), length)] | |
# Usage, Using Pyrogram | |
text = 'some really long text' | |
for m in split_message(text): | |
app.send_message('me', m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment