How to find out the package download count from a PPA?

I'd like to know how many downloads of a given package in a PPA there have been since it was first published.

I remember there was a bug about it about getting these metrics on the web UI, but as far as I know, it never got implemented.

But I think the number of downloads can nevertheless be obtained via the Launchpad API if I'm the owner of that PPA. Any pointers?


Solution 1:

Check out this script:

#!/usr/bin/python2

# Usage python ppastats.py PPATEAM (ex: webupd8team) PPA (ex: gthumb) DIST (Ubuntu version eg maverick) ARCH (ubuntu arch eg i386 or amd64)
# Example - highest downloaded file: python ppastats.py webupd8team y-ppa-manager maverick amd64 | tr '\t' ',' | cut -d ',' -f3 | sort -gr

import sys
from launchpadlib.launchpad import Launchpad

PPAOWNER = sys.argv[1]
PPA = sys.argv[2]
desired_dist_and_arch = 'https://api.launchpad.net/devel/ubuntu/' + sys.argv[3] + '/' + sys.argv[4]

cachedir = "~/.launchpadlib/cache/"
lp_ = Launchpad.login_anonymously('ppastats', 'production', cachedir)
owner = lp_.people[PPAOWNER]
archive = owner.getPPAByName(name=PPA)

for individualarchive in archive.getPublishedBinaries(status='Published', distro_arch_series=desired_dist_and_arch):
    x = individualarchive.getDownloadCount()
    if x > 0:
        print individualarchive.binary_package_name + "\t" + individualarchive.binary_package_version + "\t" + str(individualarchive.getDownloadCount())
    elif x < 1:
        print '0'

To use it:

python ppastats.py webupd8team themes natty i386

Solution 2:

You can generate an HTML report containing statistics and graphs about download counts of a PPA with ppastats (http://wpitchoune.net/blog/ppastats/).

Here is an example: http://wpitchoune.net/ppastats/ppa/otto-kesselgulasch/gimp/.

If you are using Ubuntu, you can install it by using the PPA ppa:jfi/ppastats:

sudo apt-add-repository ppa:jfi/ppastats
sudo apt-get update
sudo apt-get install ppastats

Then to generate the HTML report:

ppastats [PPA_OWNER] [PPA_NAME] -o [OUTPUT_DIR]