From 20e96e1e0737697e90dffb89cf201b4c2694355a Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 18:17:05 +0800 Subject: [PATCH 1/3] Added (currently unused) method for retrieving steam data through steam. --- config.default | 3 ++- plugins/steam.py | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/config.default b/config.default index 1d0c4b5..c3f99a1 100644 --- a/config.default +++ b/config.default @@ -32,7 +32,8 @@ "wunderground": "", "googletranslate": "", "rdio_key": "", - "rdio_secret": "" + "rdio_secret": "", + "steam_key": "" }, "permissions": { "admins": { diff --git a/plugins/steam.py b/plugins/steam.py index c1190c4..2ec76cc 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -1,6 +1,10 @@ +import urllib2 +import re +import json +from xml.dom import minidom from util import hook, http, web, text from bs4 import BeautifulSoup -import re + db_ready = False @@ -20,6 +24,32 @@ def db_init(db): db_ready = True +def get_steam_info(name): + dom = minidom.parse(urllib2.urlopen(re.sub("{USER}", name, "http://steamcommunity.com/id/{USER}/?xml=1"))) + ID = int(dom.getElementsByTagName("steamID64")[0].firstChild.data) + key = bot.config.get("api_keys", {}).get("steam_key") + url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={}&steamid={}&format=json".format(key, + ID) + data = json.load(urllib2.urlopen(url)) + useable = data['response']['games'] + games = [] + played = [] + data = {} + playtime = 0 + for x in useable: + games.append(x) + if x['playtime_forever'] > 0: + played.append(x) + playtime += x['playtime_forever'] + played.sort(key=lambda x: x['playtime_forever']) + played.reverse() + data['playtime'] = int(playtime / 60.0) + data['played'] = played + data['games'] = games + data['%played'] = round(float(len(played)) / len(games) * 100, 2) + return data + + @hook.command('sc', autohelp=False) @hook.command(autohelp=False) def steamcalc(inp, nick='', db=None): @@ -65,7 +95,7 @@ def steamcalc(inp, nick='', db=None): print e return u"\x02Unable to retrieve info for {}!\x02 Is it a valid SteamCommunity profile username ({})? " \ "Check if your profile is private, or go here to search: {}".format( - inp, web.try_isgd("http://steamcommunity.com/id/%s" % inp), web.try_isgd(url)) + inp, web.try_isgd("http://steamcommunity.com/id/%s" % inp), web.try_isgd(url)) nextone = False status = "Unknown" From 363d0ba6d9c0a2fbbca9912c8e8ff9b0b590d9f6 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 11:20:34 +0800 Subject: [PATCH 2/3] I should check data more often. --- plugins/bitcoin.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/bitcoin.py b/plugins/bitcoin.py index adf985b..a644407 100755 --- a/plugins/bitcoin.py +++ b/plugins/bitcoin.py @@ -7,10 +7,10 @@ def bitcoin(inp, say=None): data = http.get_json("https://data.mtgox.com/api/2/BTCUSD/money/ticker") data = data['data'] ticker = { - 'buy': data['buy']['display_short'], - 'high': data['high']['display_short'], - 'low': data['low']['display_short'], - 'vol': data['vol']['display_short'], + 'buy': data['buy']['display_short'].encode('ascii','ignore'), + 'high': data['high']['display_short'].encode('ascii','ignore'), + 'low': data['low']['display_short'].encode('ascii','ignore'), + 'vol': data['vol']['display_short'].encode('ascii','ignore'), } - say("Current: \x0307{}\x0f - High: \x0307{}\x0f" - " - Low: \x0307{}\x0f - Volume: {}".format(data['buy'],data['high'],data['low'],data['vol'])) + say("Current: \x0307{!s}\x0f - High: \x0307{!s}\x0f" + " - Low: \x0307{!s}\x0f - Volume: {!s}".format(ticker['buy'],ticker['high'],ticker['low'],ticker['vol'])) From d39e101f45197860b01060f09b0cca0db5bb46b8 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Fri, 6 Sep 2013 11:51:01 +0800 Subject: [PATCH 3/3] Help can return over two lines. --- plugins/help.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/help.py b/plugins/help.py index 4a353b9..f6b5143 100755 --- a/plugins/help.py +++ b/plugins/help.py @@ -23,20 +23,23 @@ def help(inp, notice=None, input=None, conn=None, bot=None): commands = dict((value, key) for key, value in funcs.iteritems()) if not inp: - out = ["", ""] + out = [""] well = [] for x in commands: well.append(x) well.sort() + count = 0 for x in well: - if len(out[0]) + len(str(x)) > 405: - out[1] += " " + str(x) + if len(out[count]) + len(str(x)) > 405: + count += 1 + out.append(str(x)) else: - out[0] += " " + str(x) + out[count] += " " + str(x) notice("Commands I recognise: " + out[0][1:]) - if out[1]: - notice(out[1][1:]) + if len(out) > 1: + for x in out[1:]: + notice(x) notice("For detailed help, do '%shelp ' where " "is the name of the command you want help for." % conn.conf["command_prefix"])