Ugly code for force-reload
This commit is contained in:
parent
5d3280b9d5
commit
9cfdc0b706
|
@ -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))
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in New Issue