From 7f86c49a29afbe672109a36d36a1582ee35f5e5c Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 2 Sep 2017 03:00:10 +0200 Subject: [PATCH] Add unlisted apps dashboard --- unlistedapps/analyze.py | 61 +++++++++++++++++++++ unlistedapps/data/.gitkeep | 0 unlistedapps/fetch.sh | 6 +++ unlistedapps/publish.py | 44 +++++++++++++++ www/template_unlistedapps.html | 99 ++++++++++++++++++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100755 unlistedapps/analyze.py create mode 100644 unlistedapps/data/.gitkeep create mode 100755 unlistedapps/fetch.sh create mode 100755 unlistedapps/publish.py create mode 100644 www/template_unlistedapps.html diff --git a/unlistedapps/analyze.py b/unlistedapps/analyze.py new file mode 100755 index 0000000..c6bef3a --- /dev/null +++ b/unlistedapps/analyze.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 + +import datetime +import glob +import os +import json +import requests + + +def githubDateToDaysAgo(date): + now = datetime.datetime.now() + date = datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ") + return (now - date).days + +official = json.loads(requests.get("https://raw.githubusercontent.com/YunoHost/apps/master/official.json").text) +community = json.loads(requests.get("https://raw.githubusercontent.com/YunoHost/apps/master/community.json").text) + +official_apps = [ os.path.basename(app["url"]) for app in official.values() ] +community_apps = [ os.path.basename(app["url"]) for app in community.values() ] + +unlisted_apps = [] + +for f in glob.glob("data/*.json"): + + j = json.loads(open(f).read()) + + for item in j["items"]: + app = { + "name": item["name"], + "url": item["html_url"], + "owner": item["owner"]["login"], + "description": item["description"], + "updated_days_ago": githubDateToDaysAgo(item["updated_at"]) + } + + if str(item["size"]) == "0": + continue + + if not app["name"].endswith("_ynh"): + continue + + if app["name"] in official_apps or app["name"] in community_apps: + continue + + app["name"] = app["name"].replace("_ynh", "") + + unlisted_apps.append(app) + +unlisted_apps = sorted(unlisted_apps, key=lambda x: x["updated_days_ago"]) + +#for app in unlisted_apps: +# print("%s %s %s %s" % (str(app["updated_days_ago"]), +# app["name"], +# app["owner"], +# app["description"])) +summary = {} +summary["unlisted_apps"] = unlisted_apps + +with open("summary.json", "w") as f: + f.write(json.dumps(summary)) + diff --git a/unlistedapps/data/.gitkeep b/unlistedapps/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/unlistedapps/fetch.sh b/unlistedapps/fetch.sh new file mode 100755 index 0000000..3c6adb5 --- /dev/null +++ b/unlistedapps/fetch.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for PAGEID in `seq 1 5` +do + curl "https://api.github.com/search/repositories?q=_ynh&sort=updated&per_page=100&page=$PAGEID" > data/$PAGEID.json +done diff --git a/unlistedapps/publish.py b/unlistedapps/publish.py new file mode 100755 index 0000000..2515076 --- /dev/null +++ b/unlistedapps/publish.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +import os +import json + +from jinja2 import Template +from ansi2html import Ansi2HTMLConverter +from ansi2html.style import get_styles + +############################################################################### + +output_dir = "../www/" + +template_path = os.path.join(output_dir,"template_unlistedapps.html") +output_path = os.path.join(output_dir,"unlistedapps.html") + +summary_path = os.path.join("./", "summary.json") + +############################################################################### + +conv = Ansi2HTMLConverter() +shell_css = "\n".join(map(str, get_styles(conv.dark_bg, conv.scheme))) + +def shell_to_html(shell): + return conv.convert(shell, False) + +############################################################################### + +if __name__ == '__main__': + + # Fetch the list of all reports, sorted in reverse-chronological order + + summary = json.load(open(summary_path)) + + # Generate the output using the template + + template = open(template_path, "r").read() + t = Template(template) + + result = t.render(data=summary, convert=shell_to_html, shell_css=shell_css) + + open(output_path, "w").write(result) + + print("Done.") diff --git a/www/template_unlistedapps.html b/www/template_unlistedapps.html new file mode 100644 index 0000000..debc720 --- /dev/null +++ b/www/template_unlistedapps.html @@ -0,0 +1,99 @@ + + + + + + Yunohost Pull Requests Dashboard + + + + + + + + + + + + + +
+ + + +
+ +
+ + + + + + + + + + + {% for app in data.unlisted_apps %} + + + + + {% endfor %} + +
DescriptionUpdated
+ {{ app.name }} + {{ app.description }}{{ app.updated_days_ago }} days ago
+ +
+ +
+ + + + +
+
+
+
+

CSS Skin/boilerplate/whatever you call it : Eden UI. Generated with Tartiflette!

+
+
+
+ + +
+ + + + + + + +