[Solved] GnomeShellExtension desc. with correct layout

Need help with C, C++, perl, python, etc?

[Solved] GnomeShellExtension desc. with correct layout

Postby Allain » 2017-06-04 15:33

Hello everyone

I am creating a script to install gnome shell extensions
I get an issue to get the description from the info page
ie this one :
https://extensions.gnome.org/extension-info/?pk=570&shell_version=3.14

if i use "| grep description" after a "wget" i get only the first line of the description
Some gnome shell extensions have a description on one line only, some not

Using the above url i get a result but i loose the layout of the description. i see only \n instead of new lines :
Code: Select all
cat gnome_shell_extensions/extn | grep -v "\"version" | grep -v "\"screenshot" | grep -v "\"creator" | grep -v "\"name" | grep -v "\"link" | grep -v "\"download" | grep -v "\"icon" | grep -v "\"uuid" | grep -v "\"pk" | sed 's/" /"/g' | sed 's/"description": //g' | sed 's/"//g'


Result :
A Gnome shell interface for todo.txt. \n\nTodo.txt is a future-proof syntax for tasks (not made by me)
for more info: http://todotxt.com/\n\nSome examples:\nTask: Basic task\n(A) Task: High priority task\nTask @project +context: Task is part of project and has a certain context\nx 2013-08-22 Task: Task was completed on the 22nd of August\n\nFor more info about the syntax: https://github.com/ginatrapani/todo.txt ... txt-Format\n\nQuick start:\nWhen you first enable the extension
chances are high you'll see a [X] in your top panel. If you click the [X]
you will be able to choose between creating the necessary files automatically or selecting your own existing files to be used with the extension.\n\nPlease use the issue tracker on the homepage to report bugs and/or file feature requests
this makes tracking easier for me. Thanks!\n\nSee the included CHANGELOG.md for info about changes between different versions
or see it online: https://bitbucket.org/bartl/todo.txt-ba ... ANGELOG.md


using
Code: Select all
sed 's/\n/\n/g' does nothing


Who knows a better way to get the complete description with a correct layout ?
Last edited by Allain on 2017-06-04 16:48, edited 1 time in total.
Allain
 
Posts: 20
Joined: 2016-12-06 13:55

Re: get a gnome shell extension description with correct lay

Postby Dai_trying » 2017-06-04 15:56

You could install jq (it's in the repo) and then something like
Code: Select all
curl -s 'https://extensions.gnome.org/extension-info/?pk=570&shell_version=3.14' | jq -r '.description'

I'm using curl here but I'm sure you can just use this as an example and modify it accordingly.
Dai_trying
 
Posts: 337
Joined: 2016-01-07 12:25

[Solved] get GnomeShellExtension description with correct la

Postby Allain » 2017-06-04 16:46

Hooo that is magic Dai_trying !

Anyway you give the first answer to all my questions on Debian User Forums
I have the habit to find the answer myself since nobody is answering.

A big thank you to you
It solved my problem
Allain
 
Posts: 20
Joined: 2016-12-06 13:55

Re: [Solved] GnomeShellExtension desc. with correct layout

Postby Dai_trying » 2017-06-04 17:22

You are welcome :)
Dai_trying
 
Posts: 337
Joined: 2016-01-07 12:25

Re: [Solved] GnomeShellExtension desc. with correct layout

Postby Allain » 2017-06-04 20:48

Anyway...

Can't sed or tr do this ?
Allain
 
Posts: 20
Joined: 2016-12-06 13:55

Re: [Solved] GnomeShellExtension desc. with correct layout

Postby Dai_trying » 2017-06-04 21:05

Quite possibly, but as this looks to me like json it seemed a good idea to use a parsing tool to separate the information.
Dai_trying
 
Posts: 337
Joined: 2016-01-07 12:25

Re: [Solved] GnomeShellExtension desc. with correct layout

Postby dasein » 2017-06-04 21:41

Allain wrote:Anyway...

Can't sed or tr do this ?

Yes and no (respectively). In particular, tr is meant to work on single characters, not multiples. Some versions of tr are said to be able to process multiple characters, and for all I know those claims may be true. I'm just not prepared to devote brain cells to remembering which version(s) of tr claim to do which thing(s).

OTOH, sed would do the job nicely, without the need for unnecessary package installation.
Code: Select all
sed 's/\\n/\n/g'

To process a file in place:
Code: Select all
sed -i 's/\\n/\n/g' input_filename

Notice that your hunch on sed syntax was very close to right.
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: [Solved] GnomeShellExtension desc. with correct layout

Postby Allain » 2017-06-05 17:28

Code: Select all
sed -i 's/\\n/\n/g' input_filename

is fine
i just missed a \

but i get only the first line of the description
some descriptions have multiple lines
and i must use all the grep -v you saw above

the only solution for now is using jq to get the complete description
and checking if the jq package exists

thank you correcting my mistake with sed
Allain
 
Posts: 20
Joined: 2016-12-06 13:55


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable