From 25f9ecfa51dc4226ec1c972ecac2a622896d0ee8 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 8 Nov 2012 21:56:56 +1300 Subject: [PATCH] Added plugin to find the total value of a Steam account --- plugins/steam.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 plugins/steam.py diff --git a/plugins/steam.py b/plugins/steam.py new file mode 100644 index 0000000..f6a8a3a --- /dev/null +++ b/plugins/steam.py @@ -0,0 +1,34 @@ +from util import hook, http, web +import re + +steamcalc_url = "http://steamcalculator.com/id/{}/{}" +count_re = re.compile(r"Found (.*?) Games with a value of ") +region = "us" # can be "us", "eu" or "uk" + + +@hook.command +def steamcalc(inp): + if " " in inp: + return "Invalid Steam ID" + + url = steamcalc_url.format(http.quote_plus(inp), region) + + try: + page = http.get_html(url) + except Exception as e: + return "Could not get Steam game listing: {}".format(e) + + try: + count = page.xpath("//div[@id='rightdetail']/text()")[0] + number = count_re.findall(count)[0] + + value = page.xpath("//div[@id='rightdetail']/h1/text()")[0] + except IndexError: + return "Could not get Steam game listing." + + try: + short_url = web.isgd(url) + except web.ShortenError as e: + short_url = url + + return u"Found {} games with a value of {}! - {}".format(number, value, short_url)