bluesky-social / cookbook

A collection of example projects and scripts for atproto development.
122 stars 15 forks source link

Text Linebreak #4

Open ohobby opened 1 year ago

ohobby commented 1 year ago

Hi,

how can i make linebreaks in the text, i post with create_bsky_post.py?

Regards, Oliver

itaru2622 commented 1 year ago

@ohobby I made short patch and sent PR as #6.

ohobby commented 11 months ago

Hi @itaru2622 it's a step further and you can already do more with it, but it would be much better if you could use \n. I would like to create a bot with which I can post certain measured values. The text is assembled in a script (and formatted with the line break) and completed with the values. At the end, the text is in a variable, which is then used for the output.

itaru2622 commented 11 months ago

@ohobby by my PR, you can pass any text to create_bsky_post.py via pipe as below.

commandofmeasurement | create_bsky_post.py --options
itaru2622 commented 11 months ago

@ohobby

even with current main branch (without my PR), you can also pass multi-line text by using quote and ENTER-key as below. but as I described above, pipe with my PR is easier than below to integrate with other software.

# current main branch (without my PR)
create_bsky_post.py  --options 'first line<ENTER>
second line<ENTER>
more lines<ENTER>
'
itaru2622 commented 10 months ago

newline char ('\n') in text is escaped to '\\n' by standard json library while it makes json object from text string.

if you prefer to use --text option with '\n' in text, you can achieve it by below.

https://github.com/bluesky-social/cookbook/blob/e8067366c1783299ee0fc15495d1e4d424ee4eda/python-bsky-post/create_bsky_post.py#L305-L309

add following line just after the above.

post["text"]=post["text"].replace("\\n","\n")

then, it gets back newline from double escaped to usual single escape.

itaru2622 commented 10 months ago

@ohobby above patch (getting back single escape from double escape) is also included in my PR #6