From a1b172ee09cfb751eb1b7853684cb1a6f6459c25 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 9 Oct 2021 13:01:59 +0200 Subject: [PATCH] Replace old broken rss feed with an html catalog news page --- app/app.py | 11 +++---- app/scripts/appListsHistory/script.py | 45 +++++++++++++++++++++++++++ app/templates/base.html | 2 +- requirements.txt | 2 +- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/app/app.py b/app/app.py index 5d87592..8f15692 100644 --- a/app/app.py +++ b/app/app.py @@ -149,12 +149,11 @@ def appsobservatory_history(): return render_template('applist_history.html', data=data) -@main.route('/appsobservatory/rss') -def appsobservatory_rss(): - file_ = open("./app/scripts/appListsHistory/atom.xml").read() - response = make_response(file_) - response.headers['Content-Type'] = 'application/rss+xml' - return response +@main.route('/appsobservatory/news') +def appsobservatory_news(): + news_per_date = json.loads(open("./app/scripts/appListsHistory/news.json").read()) + return render_template('applist_news.html', news_per_date=reversed(news_per_date.items())) + @main.route('/appsobservatory/unlisted') def appsobservatory_unlisted(): diff --git a/app/scripts/appListsHistory/script.py b/app/scripts/appListsHistory/script.py index b3e07f1..8947b53 100644 --- a/app/scripts/appListsHistory/script.py +++ b/app/scripts/appListsHistory/script.py @@ -13,6 +13,7 @@ from app import db, create_app from app.models.appcatalog import App app_ = create_app() + def _time_points_until_today(): year = 2017 @@ -129,6 +130,49 @@ def make_count_summary(): db.session.commit() +def make_news(): + + news_per_date = {d.strftime("%b %d %Y"): {"broke": [], "repaired": [], "removed": [], "added": []} for d in time_points_until_today} + previous_j = {} + + def level(infos): + lev = infos.get("level") + if lev is None or (isinstance(lev, str) and not lev.isdigit()): + return -1 + else: + return int(lev) + + + for d in time_points_until_today: + d_label = d.strftime("%b %d %Y") + + print("Analyzing %s ..." % d.strftime("%y-%m-%d")) + + # Load corresponding json + j = json.loads(open("./.work/merged_lists.json.%s" % d.strftime("%y-%m-%d")).read()) + + apps_current = set(k for k, infos in j.items() if infos["state"] in ["working", "official"] and level(infos) != -1) + apps_current_good = set(k for k, infos in j.items() if k in apps_current and level(infos) > 4) + apps_current_broken = set(k for k, infos in j.items() if k in apps_current and level(infos) <= 4) + + apps_previous = set(k for k, infos in previous_j.items() if infos["state"] in ["working", "official"] and level(infos) != -1) + apps_previous_good = set(k for k, infos in previous_j.items() if k in apps_previous and level(infos) > 4) + apps_previous_broken = set(k for k, infos in previous_j.items() if k in apps_previous and level(infos) <= 4) + + news = news_per_date[d_label] + for app in set(apps_previous_good & apps_current_broken): + news["broke"].append((app, j[app]["url"])) + for app in set(apps_previous_broken & apps_current_good): + news["repaired"].append((app, j[app]["url"])) + for app in set(apps_current - apps_previous): + news["added"].append((app, j[app]["url"])) + for app in set(apps_previous - apps_current): + news["removed"].append((app, previous_j[app]["url"])) + + previous_j = j + + json.dump(news_per_date, open('news.json', 'w')) + def update_catalog_stats(app, history): @@ -146,3 +190,4 @@ def update_catalog_stats(app, history): get_lists_history() make_count_summary() +make_news() diff --git a/app/templates/base.html b/app/templates/base.html index 791711a..fc546c8 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -43,7 +43,7 @@ diff --git a/requirements.txt b/requirements.txt index 986897a..cc9806f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ Flask==1.0.2 -Flask-Migrate +Flask-Migrate<3.0 Flask-SQLAlchemy Flask-Script Jinja2