From 9cfdc0b70699ba73b531fa23eed2feb5ef850da8 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Tue, 25 Feb 2014 13:36:52 +1300 Subject: [PATCH] Ugly code for force-reload --- plugins/minecraft_ping.py | 1 + plugins/steam_calc.py | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/plugins/minecraft_ping.py b/plugins/minecraft_ping.py index 3a6ccee..206e047 100644 --- a/plugins/minecraft_ping.py +++ b/plugins/minecraft_ping.py @@ -101,6 +101,7 @@ def mcping_modern(host, port): max_players = data["players"]["max"] online = data["players"]["online"] except Exception as e: + # TODO: except Exception is bad traceback.print_exc(e) raise PingError("Unknown Error: {}".format(e)) diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index 30b656e..b67ed88 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -38,12 +38,15 @@ def steamcalc(inp, reply=None): """steamcalc [currency] - Gets value of steam account and total hours played. Uses steamcommunity.com/id/. """ - name = inp.strip() + # check if the user asked us to force reload + force_reload = inp.endswith(" forcereload") + if force_reload: + name = inp[:-12].strip().lower() + else: + name = inp.strip() - try: - request = get_data(name) - do_refresh = True - except (http.HTTPError, http.URLError): + + if force_reload: try: reply("Collecting data, this may take a while.") refresh_data(name) @@ -51,6 +54,18 @@ def steamcalc(inp, reply=None): do_refresh = False except (http.HTTPError, http.URLError): return "Could not get data for this user." + else: + try: + request = get_data(name) + do_refresh = True + except (http.HTTPError, http.URLError): + try: + reply("Collecting data, this may take a while.") + refresh_data(name) + request = get_data(name) + do_refresh = False + except (http.HTTPError, http.URLError): + return "Could not get data for this user." csv_data = StringIO.StringIO(request) # we use StringIO because CSV can't read a string reader = unicode_dictreader(csv_data)