Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Linebreak #4

Open
ohobby opened this issue Oct 15, 2023 · 6 comments · May be fixed by #6
Open

Text Linebreak #4

ohobby opened this issue Oct 15, 2023 · 6 comments · May be fixed by #6

Comments

@ohobby
Copy link

ohobby commented Oct 15, 2023

Hi,

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

Regards,
Oliver

@itaru2622
Copy link

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

@ohobby
Copy link
Author

ohobby commented Dec 27, 2023

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
Copy link

itaru2622 commented Dec 28, 2023

@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
Copy link

@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
Copy link

itaru2622 commented Jan 21, 2024

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.

post = {
"$type": "app.bsky.feed.post",
"text": args.text,
"createdAt": now,
}

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants