You are not logged in.

#1 2022-08-27 12:37:06

mamograg17
Member
From: Kingdom of Morocco
Registered: 2022-02-08
Posts: 40

[SOLVED]How to get a random package from arch repository web interface

Hello,
I am developing a GUI application that retrieves applications' information from arch repository interface as json format, now i want to show some random packages to user when he scrolls, but i found no option to do it,

please any idea ?

Last edited by mamograg17 (2022-08-27 13:07:27)

Offline

#2 2022-08-27 12:58:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [SOLVED]How to get a random package from arch repository web interface

pkgname=$(pacman -Ssq | shuf | sed 1q)

Or, without more context, perhaps something like this would suffice.

Last edited by Trilby (2022-08-27 12:59:54)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-08-27 13:05:38

mamograg17
Member
From: Kingdom of Morocco
Registered: 2022-02-08
Posts: 40

Re: [SOLVED]How to get a random package from arch repository web interface

Trilby wrote:
pkgname=$(pacman -Ssq | shuf | sed 1q)

Or, without more context, perhaps something like this would suffice.

That's it!

Thank you, i'll put the packages' output in a string and get it information and show it.

Offline

#4 2022-08-27 13:22:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [SOLVED]How to get a random package from arch repository web interface

Okay ... I'm glad that helped ... kinda'

I doubt you are writing this application in bash.  So this was rather more to clarify the question.  I find it unlikely that you'd be using a programming language without knowing how to select a random element from a list in that language.  So I'm not sure how showing it being done in bash (which is a poor way of doing it) could be all that useful.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2022-08-28 12:40:30

mamograg17
Member
From: Kingdom of Morocco
Registered: 2022-02-08
Posts: 40

Re: [SOLVED]How to get a random package from arch repository web interface

Trilby wrote:

Okay ... I'm glad that helped ... kinda'

I doubt you are writing this application in bash.  So this was rather more to clarify the question.  I find it unlikely that you'd be using a programming language without knowing how to select a random element from a list in that language.  So I'm not sure how showing it being done in bash (which is a poor way of doing it) could be all that useful.

Actually no, I am not writing in bash, I use C++ to make a GUI package manager.

Actually I know how to get a random thing in C++ but it wasn't helpful in my situation, cause I want a correct name to display.

Offline

#6 2022-10-01 18:52:53

mamograg17
Member
From: Kingdom of Morocco
Registered: 2022-02-08
Posts: 40

Re: [SOLVED]How to get a random package from arch repository web interface

Trilby wrote:
pkgname=$(pacman -Ssq | shuf | sed 1q)

Hello again, the command works perfectly but I have a little problem, how can I get popular only packages because this command gives me some unpopular tools, please any idea.

Offline

#7 2022-10-01 19:59:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [SOLVED]How to get a random package from arch repository web interface

mamograg17 wrote:

Actually I know how to get a random thing in C++ but it wasn't helpful in my situation, cause I want a correct name to display.

And if you select a random item from the list in C++, you'll have a correct name to display.  I'm just not sure how a bash example of selecting a random item from a list helps with a C++ project.

mamograg17 wrote:

how can I get popular only packages because this command gives me some unpopular tools, please any idea.

What do you mean by popular?  The repo databases and web interface has no "popularity" data.  But in any case, once you define what popular is, it's still the same situation that you just need to select a random item from a list which in a shell could be done by piping to shuf and sed (or head) but that's completely irrelevant for C++ code.

Last edited by Trilby (2022-10-01 20:00:07)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2022-10-01 20:03:53

mamograg17
Member
From: Kingdom of Morocco
Registered: 2022-02-08
Posts: 40

Re: [SOLVED]How to get a random package from arch repository web interface

Trilby wrote:

how can I get popular only packages because this command gives me some unpopular tools, please any idea.
What do you mean by popular?  The repo databases and web interface has no "popularity" data.  But in any case, once you define what popular is, it's still the same situation that you just need to select a random item from a list which in a shell could be done by piping to shuf and sed (or head) but that's completely irrelevant for C++ code.

getting the name that the command outputs is easy, by popular i mean applications like chrome, brave, telegram, steam... you can say most downloaded.
but you said that there is no poplarity data.

Offline

#9 2022-10-01 20:15:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [SOLVED]How to get a random package from arch repository web interface

mamograg17 wrote:

by popular i mean applications like chrome, brave, telegram, steam...

Eh, okay, if you really want to define it that way:

printf "%s\n" chrome brave telegram steam | shuf | sed 1q
mamograg17 wrote:

you can say most downloaded.

I can say a lot of things.  You need to decide what you want.  Pkgstats has a json API and provides a "popularity" metric, but it is not based (directly) on the most downloaded.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2022-10-01 20:18:41

mamograg17
Member
From: Kingdom of Morocco
Registered: 2022-02-08
Posts: 40

Re: [SOLVED]How to get a random package from arch repository web interface

Trilby wrote:

I can say a lot of things.  You need to decide what you want.  Pkgstats has a json API and provides a "popularity" metric, but it is not based (directly) on the most downloaded.

i think that's what i need, how can i use it please?

Offline

#11 2022-10-01 21:46:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [SOLVED]How to get a random package from arch repository web interface

Start here, then perhaps review this, then RTFW/STFW.

Last edited by Trilby (2022-10-01 21:48:23)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB