Skip to content

Instantly share code, notes, and snippets.

@MichaelTunnell
Last active August 10, 2017 03:05
Show Gist options
  • Save MichaelTunnell/8d290e2002bdbfb8ac7634d13c0be4a1 to your computer and use it in GitHub Desktop.
Save MichaelTunnell/8d290e2002bdbfb8ac7634d13c0be4a1 to your computer and use it in GitHub Desktop.
python script that pulls download stats data from Launchpad.net PPAs
from launchpadlib.launchpad import Launchpad
import os
import sys
USERNAME=sys.argv[1]
PPA=sys.argv[2]
PACKAGE=sys.argv[3]
cachedir = os.environ['HOME'] + '/.launchpadlib/cache/'
launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir)
ppa = launchpad.people[USERNAME].getPPAByName(name=PPA)
bins = ppa.getPublishedBinaries(binary_name=PACKAGE)
builds = []
total = 0
for bin in bins:
count = bin.getDownloadCount()
total += count
if (count > 0):
builds.append([count,'%s %s' % (bin.binary_package_name,bin.binary_package_version)])
builds_sorted = sorted(builds,key=lambda count: count[0],reverse=True)
for build in builds_sorted:
print '%s:%s' % (build[0], build[1])
@MichaelTunnell
Copy link
Author

MichaelTunnell commented May 19, 2017

this was forked from springmeyer's gist, I added command line value input rather than hardcoded in the script.

Usage:

  1. sudo apt install python-launchpadlib
  2. cd to the folder where you put the script
  3. run the script with the value order of "PPA owner's username" "ppa name" "package name"
  • example: python launchpad-ppa-stats.py plushuang-tw uget-stable uget > launchpad-ppa-stats.txt

Note: the > launchpad-ppa-stats.txt portion is not needed but this is to output to a text file where as by default the script outputs the data to the terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment