Merge pull request #113 from blha303/patch-1

steam.py - Fix page scraping, use markdown instead, PLUGIN IS NO LONGER BROKEN!
This commit is contained in:
Luke Rogers 2013-08-14 01:22:23 -07:00
commit 08b1e82f41

View file

@ -57,14 +57,23 @@ def steamcalc(inp, nick='', db=None):
url = http.prepare_url("http://steamdb.info/calculator/", {"player": inp, "currency": currency if currency else "us"})
soup = http.get_soup(url)
out = u""
try:
name = soup.findAll('h1', {'class': 'header-title'})[1].text
status = soup.findAll('td')[7].text
out += soup.findAll('h1', {'class': 'header-title'})[1].text.strip()
except Exception as e:
print e
return u"\x02Unable to retrieve info for %s!\x02 Is it a valid SteamCommunity profile username (%s)? " \
"Check if your profile is private, or go here to search: %s" % (inp, web.try_isgd("http://steamcommunity.com/id/%s" % inp), web.try_isgd(url))
nextone = False
status = "Unknown"
for i in soup.findAll('td'):
if nextone:
status = i.text
break
elif i.text == "Status":
nextone=True
if status == "Online":
status = "\x033\x02Online\x02\x0f"
elif status == "Offline":
@ -75,41 +84,25 @@ def steamcalc(inp, nick='', db=None):
status = "\x035\x02Busy\x02\x0f"
elif "Looking to" in status:
status = "\x036\x02%s\x02\x0f" % status
out += " (%s)" % status
out = ""
try:
twdata = soup.find('h1', {'class': 'header-title pull-right'}).find('a')['data-text'].split(", ")
money = twdata[0].split("My #Steam account is worth ")[1]
time = twdata[1].split("and I spent ")[1].split(" playing games!")[0]
for i in soup.findAll('div', {'class': 'panel'}):
if str(i.find('div', {'class': 'panel-heading'})) == '<div class="panel-heading">Markdown</div>':
data = i
data = data.findAll('p')[1:]
money = data[0].text.split(" ")[-1]
totalgames = data[1].text.split(" ")[-1]
notplayed = data[2].text.split(" ")[-1]
nppercent = data[3].text.split(" ")[-1]
time = data[4].text.split(" ")[-1].replace("h", "hours")
out += " This account is worth \x02%s\x02, and they've spent \x02%s\x02 playing games! " % (money, time)
except:
pass
try:
timeonsteam = soup.findAll('i')[1].text[1:-1].split(" ")
timestamp = datetime.strptime(timeonsteam[0]+" "+timeonsteam[1]+" "+timeonsteam[2] + " - " + timeonsteam[4]+" "+timeonsteam[5], "%B %d, %Y - %H:%M:%S UTC")
timeonsteam = timesince.timesince(timestamp)
out += "Their account was created %s ago! " % timeonsteam
except:
pass
try:
totalgames = soup.find('b').text
notplayed = soup.findAll('b')[1].text
nppercent = soup.findAll('i')[3].text[1:-1]
out += "They have \x02%s games\x02, but \x02%s of them haven't been played\x02! That's \x02%s\x02! " % (totalgames, notplayed, nppercent)
except:
pass
out += " They have \x02%s games\x02, but \x02%s of them haven't been touched\x02! That's \x02%s\x02! " % (totalgames, notplayed, nppercent)
if not dontsave:
db.execute("insert or replace into steam(nick, acc) values (?,?)", (nick.lower(), inp))
db.commit()
if not out:
return "I couldn't read the information for that user. %s" % web.try_isgd(url)
return u"%s (%s): %s%s" % (name.strip(), status, out, web.try_isgd(url))
return out + web.try_isgd(url)
def get_steam_info(url):