Improve sorting of appci

This commit is contained in:
Alexandre Aubin 2017-08-29 00:24:31 +02:00
parent 783fc2885d
commit ae05f42bb7

View file

@ -20,21 +20,26 @@ def main():
applevel = appdata.split("\n")[1][0] applevel = appdata.split("\n")[1][0]
appdata = appdata.split("\n")[0] appdata = appdata.split("\n")[0]
data["level"] = applevel data["level"] = int(applevel)
statusescore = 0
for c in appdata: for c in appdata:
if c == "0": if c == "0":
s = "danger" s = "danger"
statusescore -= 1
elif c == "1": elif c == "1":
s = "success" s = "success"
statusescore += 1
else: else:
s = "unknown" s = "unknown"
data["statuses"].append(s) data["statuses"].append(s)
data["statusescore"] = statusescore
apps.append(data) apps.append(data)
apps.sort(key=lambda a: a["level"], reverse=True) apps.sort(key=lambda a: (a["level"], a["statusescore"], a["name"])), reverse=True)
with open("apps.json", "w") as f: with open("apps.json", "w") as f:
json.dump(apps, f) json.dump(apps, f)