diff options
author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2022-08-04 17:01:43 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2022-08-04 17:26:48 +0900 |
commit | 978611599094c21d4b2865f417479795608c4a83 (patch) | |
tree | d14a7cd55011e85fa944c9bc0ca92522ab194629 /src/rsskey.py | |
parent | 9162549a27b02f5f9ce9adea3b957618db460779 (diff) | |
download | rsskey-0.2.0.tar.gz |
Introduce option 'cw' for this and rename 'limit' to 'text' for clarity.
Diffstat (limited to 'src/rsskey.py')
-rwxr-xr-x | src/rsskey.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/rsskey.py b/src/rsskey.py index c8acf53..91bf789 100755 --- a/src/rsskey.py +++ b/src/rsskey.py @@ -27,6 +27,12 @@ from markdownify import markdownify as md from trio import open_nursery, run +def truncate(string, length, end='…'): + """Return string truncated to length, ending with given character.""" + if len(string) <= length: return string + return string[:length-len(end)] + end + + async def create(client, **note): """Create the given note and return its ID.""" response = await client.post('notes/create', json=note) @@ -42,12 +48,13 @@ async def post(job, client, link, title, summary): 'userId': job['user']}) if search.json(): return - note = partial(create, client, i=job['token'], visibility='home', cw=title) + note = partial(create, client, i=job['token'], visibility='home', + cw=truncate(title, job.getint('cw'))) original = f'Original: {link}' rest = '\n\n'.join((*map(partial(sub, r'\s+', ' '), split(r'\s*\n{2,}\s*', md(summary).strip())), original)) - limit = int(job['limit']) + limit = job.getint('text') parent = None while len(rest) > limit: |