Skip to content

Instantly share code, notes, and snippets.

@nathan-osman
Created July 14, 2017 16:56
Show Gist options
  • Save nathan-osman/b9158d058cc45916dcd20a591b66d0b4 to your computer and use it in GitHub Desktop.
Save nathan-osman/b9158d058cc45916dcd20a591b66d0b4 to your computer and use it in GitHub Desktop.
Updated script for retrieving PPA download counts - https://askubuntu.com/a/296200/5
#!/usr/bin/env python2
from argparse import ArgumentParser
from sys import exit
try:
from launchpadlib.launchpad import Launchpad
from tabulate import tabulate
except ImportError:
print "python-launchpadlib and python-tabulate are required"
exit(1)
class StatFetcher:
"""
Retrieve download statistics for a PPA
"""
def __init__(self, user, ppa):
self._user = user
self._ppa = ppa
def _login(self):
self._lp = Launchpad.login_anonymously(
'ppastats',
'production',
)
u = self._lp.people[self._user]
self._archive = u.getPPAByName(name=self._ppa)
def _print_counts(self):
print "Retrieving statistics..."
print
d = []
for b in self._archive.getPublishedBinaries():
s = b.distro_arch_series
d.append((
b.binary_package_name,
b.binary_package_version,
s.display_name,
b.getDownloadCount(),
))
print tabulate(d, headers=(
'Name',
'Version',
'Series',
'Downloads',
))
def go(self):
self._login()
self._print_counts()
if __name__ == '__main__':
parser = ArgumentParser(description="Retrieve download statistics for a PPA")
parser.add_argument(
'user',
help="name of Launchpad user or team",
)
parser.add_argument(
'ppa',
help="name of PPA",
)
args = parser.parse_args()
StatFetcher(args.user, args.ppa).go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment