Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evandandrea/81639efeb3cf4d9d658c4d65a026e1c7 to your computer and use it in GitHub Desktop.
Save evandandrea/81639efeb3cf4d9d658c4d65a026e1c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
'''Print every stable snap in the Ubuntu store, sorted by first publication.
For example:
2017-02-08T08:51:17.326613Z openmvs
2017-02-08T10:32:53.331479Z anta-i7z
2017-02-08T10:38:35.496156Z cpufreq
2017-02-08T21:06:24.386841Z verum-cli
2017-02-09T03:19:58.789293Z wuzz
'''
import urllib.request
import json
url = 'https://search.apps.ubuntu.com/api/v1/snaps/search'
params = '?fields=name,date_published&confinement='
next_page = url + params
all_packages = {}
while True:
data = urllib.request.urlopen(next_page).read().decode('utf8')
data = json.loads(data)
for package in data['_embedded']['clickindex:package']:
name = package['name'].split('.')[0]
published = package['date_published']
all_packages[name] = published
if data['_links'].get('next'):
next_page = data['_links']['next']['href']
# Bug in click-package-index
next_page += '&confinement='
else:
break
for package in sorted(all_packages, key=all_packages.get):
print(all_packages[package], package)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment