From 8ce7859f088e11d57168d557dde9b1ecee4fe286 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Wed, 1 Aug 2018 03:31:50 +0200 Subject: [PATCH] Show number of reviews in table. --- dailyreleases/main.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/dailyreleases/main.py b/dailyreleases/main.py index 88957bf..7f66a3f 100644 --- a/dailyreleases/main.py +++ b/dailyreleases/main.py @@ -300,29 +300,34 @@ class DailyReleasesBot(object): # The sub-tables for updates will use the entire rls_name as the name, while games and dlcs will show # tags and highlights, as well as the actual game_name - if type_name == "Updates": - name = lambda r: "[{name}]({nfo})".format(name=r["rls_name"], nfo=r["nfo_link"]) - else: - tags = lambda r: " ({})".format(" ".join(r["tags"])) if r["tags"] else "" - highlights = lambda r: " **- {}**".format(", ".join(r["highlights"])) if r["highlights"] else "" - name = lambda r: "[{name}{tags}]({nfo}){highlights}".format(name=r["game_name"], - tags=tags(r), - nfo=r["nfo_link"], - highlights=highlights(r)) - review = lambda r: "{:.0%}".format(r["review_score"]) if r["review_score"] != -1 else "-" - store = lambda r: "[{}]({})".format(r["store_name"], r["store_link"]) + def row(r): + if type_name == "Updates": + name = "[{}]({})".format(r["rls_name"], r["nfo_link"]) + else: + tags = " ({})".format(" ".join(r["tags"])) if r["tags"] else "" + highlights = " **- {}**".format(", ".join(r["highlights"])) if r["highlights"] else "" + name = "[{}{}]({}){}".format(r["game_name"], tags, r["nfo_link"], highlights) - # Releases in these sub-tables are grouped by release group, and the groups are ordered according to the + if r["review_score"] != -1: + review_score = "{:.0%} ^^\({}\)".format(r["review_score"], r["popularity"]) + else: + review_score = "-" + + store = "[{}]({})".format(r["store_name"], r["store_link"]) + + return name, r["group"], review_score, store + + # Releases in the sub-tables are grouped by release group, and the groups are ordered according to the # most popular game within the group. Games are sorted by popularity internally in the groups. - max_group_popularity = defaultdict(int) + group_popularity = defaultdict(int) for rls in type_releases: - max_group_popularity[rls["group"]] = max(max_group_popularity[rls["group"]], rls["popularity"]) + group_popularity[rls["group"]] = max(group_popularity[rls["group"]], rls["popularity"]) - table = [(name(rls), rls["group"], review(rls), store(rls)) + table = [row(rls) for rls in sorted(type_releases, - key=lambda r: (max_group_popularity[r["group"]], r["popularity"]), + key=lambda r: (group_popularity[r["group"]], r["group"], r["popularity"]), reverse=True)] - post.append(tabulate(table, headers=(type_name, "Group", "Reviews", "Store"), tablefmt="pipe")) + post.append(tabulate(table, headers=(type_name, "Group", "Score", "Store"), tablefmt="pipe")) post.append("") post.append(" ")