From d109ce92c5087755b3726a73c36ff80eaddbf1b8 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Fri, 3 Aug 2018 03:30:17 +0200 Subject: [PATCH] Sort RIPs after non-RIPs. Uglify output table per YouSmellFunky's request. Removes dependency on tabulate. Rename Games->Game, Updates->Update in table header. Abbreviate number of reviews using SI prefixes. --- dailyreleases/main.py | 108 +++++++++++++++++++----------------- dailyreleases/steam.py | 16 ++++-- dailyreleases/util.py | 25 +++++++++ setup.py | 3 +- tests/test_parse_dirname.py | 35 ++++++------ 5 files changed, 112 insertions(+), 75 deletions(-) diff --git a/dailyreleases/main.py b/dailyreleases/main.py index 2e971d2..2a815ce 100644 --- a/dailyreleases/main.py +++ b/dailyreleases/main.py @@ -10,9 +10,8 @@ from datetime import datetime, timedelta import prawcore import requests_cache -from tabulate import tabulate -from dailyreleases import config, __version__ +from dailyreleases import config, __version__, util from dailyreleases.gog import GOG from dailyreleases.predb import Predb from dailyreleases.reddit import Reddit @@ -148,16 +147,15 @@ class DailyReleasesBot(object): else: platform = "Windows" - # Find type (games/dlc/updates) - rls_type = "Games" - - # Order of the if-statements is important: update trumps dlc because an update to a DLC is an update, not a dlc! + # Find type (game/dlc/update) + # Order of the if-statements is important: Update trumps DLC because an update to a DLC is an update, not a DLC! + rls_type = "Game" if re.search("(? str: + """ + Return a humanized string representation of a number (of bytes). + Adapted from Doug Latornell - http://code.activestate.com/recipes/577081/ + """ + abbrevs = { + "dec": [ + (1000 ** 5, 'P' + suffix), + (1000 ** 4, 'T' + suffix), + (1000 ** 3, 'G' + suffix), + (1000 ** 2, 'M' + suffix), + (1000 ** 1, 'k' + suffix) + ], + "bin": [ + (1 << 50, 'Pi' + suffix), + (1 << 40, 'Ti' + suffix), + (1 << 30, 'Gi' + suffix), + (1 << 20, 'Mi' + suffix), + (1 << 10, 'ki' + suffix) + ] + } + factor, suffix = next(((f, s) for f, s in abbrevs[prefix] if n >= f), (1, suffix)) + return "{1:.{0}f}".format(precision, n / factor).rstrip("0").rstrip(".") + suffix + + def case_insensitive_close_matches(word, possibilities, n=3, cutoff=0.6): """ Python's difflib.get_close_matches does case sensitive sequence matching, this function decorates the library diff --git a/setup.py b/setup.py index c97a0e6..ad79f25 100644 --- a/setup.py +++ b/setup.py @@ -40,8 +40,7 @@ setup( "requests", "requests_cache", "praw", - "beautifulsoup4", - "tabulate" + "beautifulsoup4" ], entry_points={ "console_scripts": [ diff --git a/tests/test_parse_dirname.py b/tests/test_parse_dirname.py index d8d5d1d..42236c9 100644 --- a/tests/test_parse_dirname.py +++ b/tests/test_parse_dirname.py @@ -14,7 +14,7 @@ class ParseDirnameTestCase(unittest.TestCase): self.assertEqual("Aztez", p["rls_name"]) self.assertEqual("Aztez", p["game_name"]) self.assertEqual("Windows", p["platform"]) - self.assertEqual("Games", p["type"]) + self.assertEqual("Game", p["type"]) self.assertEqual("DARKSiDERS", p["group"]) self.assertIn("store.steampowered.com/app/244750", p["store_links"]["Steam"]) self.assertEqual([], p["tags"]) @@ -27,7 +27,7 @@ class ParseDirnameTestCase(unittest.TestCase): def test_update(self): p = self.bot.parse_dirname("Car.Mechanic.Simulator.2018.Plymouth.Update.v1.5.1.Hotfix-PLAZA") - self.assertEqual("Updates", p["type"]) + self.assertEqual("Update", p["type"]) def test_proper_highlight(self): p = self.bot.parse_dirname("Death.Coming.PROPER-SiMPLEX") @@ -36,17 +36,17 @@ class ParseDirnameTestCase(unittest.TestCase): def test_macos_release(self): p = self.bot.parse_dirname("The_Fall_Part_2_Unbound_MacOS-Razor1911") self.assertEqual("Mac OSX", p["platform"]) - self.assertEqual("Games", p["type"]) + self.assertEqual("Game", p["type"]) def test_macosx_update(self): p = self.bot.parse_dirname("Man_O_War_Corsair_Warhammer_Naval_Battles_v1.3.2_MacOSX-Razor1911") self.assertEqual("Mac OSX", p["platform"]) - self.assertEqual("Updates", p["type"]) + self.assertEqual("Update", p["type"]) def test_linux_release(self): p = self.bot.parse_dirname("Sphinx_And_The_Cursed_Mummy_Linux-Razor1911") self.assertEqual("Linux", p["platform"]) - self.assertEqual("Games", p["type"]) + self.assertEqual("Game", p["type"]) def test_dlc_explicit(self): p = self.bot.parse_dirname("Fallout.4.Far.Harbor.DLC-CODEX") @@ -59,30 +59,31 @@ class ParseDirnameTestCase(unittest.TestCase): def test_incl_dlc_update(self): p = self.bot.parse_dirname("Wolfenstein.II.The.New.Colossus.Update.5.incl.DLC-CODEX") - self.assertEqual("Updates", p["type"]) + self.assertEqual("Update", p["type"]) def test_incl_dlc_release(self): p = self.bot.parse_dirname("Mutiny.Incl.DLC-DARKSiDERS") - self.assertEqual("Games", p["type"]) + self.assertEqual("Game", p["type"]) - def test_popularity_steam(self): + def test_score_steam(self): p1 = self.bot.parse_dirname("BioShock_Infinite-FLT") p2 = self.bot.parse_dirname("Duke.Nukem.Forever.Complete-PLAZA") - self.assertGreater(p1["popularity"], p2["popularity"]) + self.assertGreater(p1["score"], p2["score"]) def test_non_steam(self): p = self.bot.parse_dirname("Battlefield.1.REPACK-CPY") self.assertIn("www.origin.com/usa/en-us/store/battlefield/battlefield-1", p["store_links"]["Origin"]) - self.assertEqual(-1, p["popularity"]) + self.assertEqual(-1, p["score"]) + self.assertEqual(-1, p["num_reviews"]) def test_gog_exclusive(self): p = self.bot.parse_dirname("Dungeons.and.Dragons.Dragonshard.v2.0.0.10.Multilingual-DELiGHT") self.assertIn("gog.com/game/dungeons_dragons_dragonshard", p["store_links"]["GOG"]) - self.assertEqual(-1, p["popularity"]) + self.assertEqual(-1, p["score"]) - def test_popularity_non_steam(self): + def test_score_non_steam(self): p = self.bot.parse_dirname("Ode.RIP.MULTI12-SiMPLEX") - self.assertEqual(-1, p["popularity"]) + self.assertEqual(-1, p["score"]) def test_tags(self): p = self.bot.parse_dirname("Teenage.Mutant.Ninja.Turtles.Portal.Power.RIP.MULTI8-SiMPLEX") @@ -95,13 +96,13 @@ class ParseDirnameTestCase(unittest.TestCase): def test_steam_package(self): p = self.bot.parse_dirname("Farming.Simulator.17.Platinum.Edition.Update.v1.5.3-BAT") self.assertEqual("Farming Simulator 17 - Platinum Edition", p["game_name"]) - self.assertEqual("Updates", p["type"]) + self.assertEqual("Update", p["type"]) self.assertIn("store.steampowered.com/sub/202103", p["store_links"]["Steam"]) def test_steam_package_with_dlc_first(self): p = self.bot.parse_dirname("The.Witcher.3.Wild.Hunt.Game.of.The.Year.Edition-RELOADED") self.assertEqual("The Witcher 3: Wild Hunt - Game of the Year Edition", p["game_name"]) - self.assertEqual("Games", p["type"]) + self.assertEqual("Game", p["type"]) self.assertIn("store.steampowered.com/sub/124923", p["store_links"]["Steam"]) def test_steam_bundle(self): @@ -109,7 +110,7 @@ class ParseDirnameTestCase(unittest.TestCase): self.assertEqual("Valve.Complete.Pack-FAKE", p["dirname"]) self.assertEqual("Valve Complete Pack", p["game_name"]) self.assertEqual("Windows", p["platform"]) - self.assertEqual("Games", p["type"]) + self.assertEqual("Game", p["type"]) self.assertIn("store.steampowered.com/bundle/232", p["store_links"]["Steam"]) def test_denuvo_eula(self): @@ -129,7 +130,7 @@ class ParseDirnameTestCase(unittest.TestCase): def test_build_is_update(self): p = self.bot.parse_dirname("DUSK.Episode.1.Build.2.6-SKIDROW") - self.assertEqual("Updates", p["type"]) + self.assertEqual("Update", p["type"]) def test_readnfo_microsoft_store(self): p = self.bot.parse_dirname("Zoo.Tycoon.Ultimate.Animal.Collection.READNFO-CODEX")