From c34404408d2a85b74aa6da181021719100bf7936 Mon Sep 17 00:00:00 2001 From: kload Date: Tue, 13 Oct 2015 15:05:58 +0200 Subject: [PATCH] [enh] Add a list builder script --- list_builder.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 list_builder.py diff --git a/list_builder.py b/list_builder.py new file mode 100644 index 0000000..6c37df7 --- /dev/null +++ b/list_builder.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python2 +import sys +import time +import json +import requests +import datetime +from dateutil.parser import parse + +try: + json_list = sys.argv[1] + token = (sys.argv[2], sys.argv[3]) +except IndexError: + print 'Usage: %s ' % sys.argv[0] + print + print 'Build a YunoHost app list from a simplfied list, output results in .new.json' + sys.exit(1) + +json_text = requests.get('https://raw.githubusercontent.com/YunoHost/apps/master/%s.json' % (json_list), auth=token).text +imported_json = json.loads(json_text) + +result_dict = {} + +for app, info in imported_json.items(): + owner, repo = filter(None, info['url'].split("/"))[-2:] + try: + res = requests.get('https://raw.githubusercontent.com/%s/%s/%s/manifest.json' % (owner, repo, info['revision']), auth=token) + except: + print 'Fail: ', info['url'] + continue + if res.status_code != 200: + print '%s returned an error %d' % (info['url'], res.status_code) + continue + + manifest = json.loads(res.text) + + try: + res = requests.get('https://api.github.com/repos/%s/%s/commits/%s' % (owner, repo, info['revision']), auth=token) + info2 = json.loads(res.text) + date = info2['commit']['author']['date'] + parsed_date = parse(date) + timestamp = int(time.mktime(parsed_date.timetuple())) + result_dict[manifest['id']] = { + 'git': { + 'branch': info['branch'], + 'revision': info['revision'], + 'url': info['url'] + }, + 'lastUpdate': timestamp, + 'manifest': manifest, + 'state': info['state'] + } + except KeyboardInterrupt: + sys.exit(1) + except Exception as e: + print 'Fail: ', manifest['id'] + print e + continue + print manifest['id'] + + +with open('%s.new.json' % json_list, 'w') as f: + f.write(json.dumps(result_dict, sort_keys=True)) + print 'Done!' + print + print 'Written in %s.new.json' % json_list