Ugly code for force-reload

This commit is contained in:
Luke Rogers 2014-02-25 13:36:52 +13:00
parent 5d3280b9d5
commit 9cfdc0b706
2 changed files with 21 additions and 5 deletions

View File

@ -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))

View File

@ -38,12 +38,15 @@ def steamcalc(inp, reply=None):
"""steamcalc <username> [currency] - Gets value of steam account and
total hours played. Uses steamcommunity.com/id/<nickname>. """
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)