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

Strip escape sequences when redirecting output to a file #8

Closed
ghost opened this issue May 9, 2019 · 3 comments
Closed

Strip escape sequences when redirecting output to a file #8

ghost opened this issue May 9, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented May 9, 2019

I'd like to save my Kobo wishlist locally in a text file, for backup purposes.

I tried with:

python kobo-book-downloader wishlist > kobo-wishlist.txt

But if I open kobo-wishlist.txt with a text editor (emacs) I get the following output:

^[[1m1984^[[0m by George Orwell (ISBN: 9780547249643)
^[[1m2001: A Space Odyssey^[[0m by Arthur C. Clarke (ISBN: 9780748120789)
...

I could easily remove those escape sequences manually with a simple find & replace, but I wonder if kobo-book-downloader can detect if its output is being redirected to a file and, in that case, strip any escape sequence automatically.

What do you think?

@ghost
Copy link
Author

ghost commented May 9, 2019

I just found a nice program called ansifilter. Basically I can fix my problem with the following command:

python kobo-book-downloader wishlist | ansifilter > kobo-wishlist.txt

I could even keep escape sequences and generate an HTML document instead:

python kobo-book-downloader wishlist | ansifilter --html > kobo-wishlist.html

TnS-hun added a commit that referenced this issue May 10, 2019
@TnS-hun
Copy link
Owner

TnS-hun commented May 10, 2019

There was a missing call and that's why those sequences were not stripped.

@ghost
Copy link
Author

ghost commented May 11, 2019

I confirm that kobo-book-downloader now strips escape sequences correctly without the need of external programs like ansifilter.

Thank you!

@ghost ghost closed this as completed May 11, 2019
This issue was closed.
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

No branches or pull requests

1 participant