~cnx/rsskey

978611599094c21d4b2865f417479795608c4a83 — Nguyễn Gia Phong 1 year, 11 months ago 9162549 main 0.2.0
Truncate long titles

Introduce option 'cw' for this and rename 'limit' to 'text' for clarity.
3 files changed, 14 insertions(+), 5 deletions(-)

M README.md
M pyproject.toml
M src/rsskey.py
M README.md => README.md +4 -2
@@ 24,8 24,10 @@ declare the mirroring jobs in `jobs.conf`, for example:
source = https://stallman.org/rss/rss.xml
; URL to destination Misskey instance's API
dest = https://birb.space/api
; Character limit of the Misskey instance
limit = 420
; Note character limit of the Misskey instance
text = 420
; Content warning character limit of the Misskey instance
cw = 69
; Misskey user ID for searching previous notes
user = 8rt4sahf1j
; Access token with permission to compose notes

M pyproject.toml => pyproject.toml +1 -1
@@ 4,7 4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "rsskey"
version = "0.1.0"
version = "0.2.0"
description = "RSS feed mirror on Misskey"
readme = "README.md"
requires-python = ">=3.7"

M src/rsskey.py => src/rsskey.py +9 -2
@@ 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: