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

Badge Request: PSGallery profile total downloads #10593

Closed
NorskNoobing opened this issue Oct 9, 2024 · 4 comments
Closed

Badge Request: PSGallery profile total downloads #10593

NorskNoobing opened this issue Oct 9, 2024 · 4 comments
Labels
service-badge New or updated service badge

Comments

@NorskNoobing
Copy link

📋 Description

This badge would dynamically get the "Total downloads of packages", which is displayed on a PSGallery profile. I'd want it to look something like this static badge mockup, together with a link to the profile when you press the badge:

You can see the total downloads value on any PSGallery profile, but here's a link to mine for reference:
https://www.powershellgallery.com/profiles/NorskNoobing

🔗 Data

There's already another badge called PowerShell Gallery Downloads, but it seems to be limited to only a single package, and therefore can't fetch the downloads of all your packages combined. It seems to be using the following API:
https://www.powershellgallery.com/api/v2

Alternatively you could also scrape the profile website i.e. my profile on the following XPaths:

//*[@id="skippedToContent"]/section/section/aside/div/div[2]/h2/text()

or

/html/body/div[2]/section/section/aside/div/div[2]/h2/text()

🎤 Motivation

I'd want this to display the total downloads across all my PSGallery modules/packages on my GitHub profile README.

@NorskNoobing NorskNoobing added the service-badge New or updated service badge label Oct 9, 2024
@chris48s
Copy link
Member

Hi. Happy to look at a PR for this the information is available via the API.

We don't take new badges that rely on scraping. Keeping them working is too high-maintenance. From https://github.com/badges/shields/blob/master/CONTRIBUTING.md#badge-guidelines

Badges should not obtain data by scraping web pages - these are likely to break frequently. Whereas API publishers are incentivised to maintain a stable platform for their users, authors of web pages have no such incentive.

@NorskNoobing
Copy link
Author

Unfortunately the people at psgallery takes about half a year to respond. It seems like they don't really monitor their support mail. Anyways, here's the answer I got from them.

We do not have an API to fetch total PS module downloads for a particular owner, but we can run queries to find this info for you.

I would interpret this as that they can provide me with the number when I ask for it, but no automation. Is it possible to run scripts when fetching the badge numbers? Here are the different implementations I've thought of:

  1. Web scraping. This is what I've used for years, and it still works properly. PSGallery has never updated their website for as long as I've had the script deployed, but I understand the fragility of this implementation.
  2. Use the API endpoint that fetches one module individually, then have a list of modules to check, and sum the download counts together.

I'm not sure if the badge/shields usually do this many calculations, but it's atleast an option.

If none of the options described are wanted, then it'll probably be best to use the 2nd option implementation through something like a GitHub action, and have a static badge/shield to show the value. The problem with this implementation is that the GitHub action would make an insane amount of commits for each time the module downloads update. This could make it difficult to find your last non-automated commit. It also inflates the number of commits you've done per day on your GitHub profile.

@chris48s
Copy link
Member

chris48s commented Feb 7, 2025

There have been some recent updates in the XML parsing library we use for the dynamic XML badge that improve the handling of HTML. So if you want to do it yourself, you could use the dynamic XML badge to do this. For example:

- https://img.shields.io/badge/dynamic/xml?url=https%3A%2F%2Fwww.powershellgallery.com%2Fprofiles%2FNorskNoobing&query=%2F%2F*%5B%40id%3D%22skippedToContent%22%5D%2Fsection%2Fsection%2Faside%2Fdiv%2Fdiv%5B2%5D%2Fh2&label=downloads

I think that is the best solution here if the only way to get the number is by scraping or making a lot of API calls.

Using a GitHub action to write out a static badge can be a great approach, but I think it works best when the metric changes (or might change) every time there is a commit to the repo or every time there is a release or whatever, rather than when the thing you're measuring changes independently of activity on the repo.

@NorskNoobing
Copy link
Author

Thanks! :) the dynamic badge is perfect for my use-case, as the psgallery devs most likely won't add an "all downloads" endpoint any time soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge New or updated service badge
Projects
None yet
Development

No branches or pull requests

4 participants
@chris48s @NorskNoobing and others