Skip to content

Instantly share code, notes, and snippets.

@muhammedfurkan
Forked from behf/split.py
Created April 25, 2020 20:22
Show Gist options
  • Save muhammedfurkan/7db29b67410c55c8d069816cb71aca40 to your computer and use it in GitHub Desktop.
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.
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