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:
commit
08b1e82f41
1 changed files with 24 additions and 31 deletions
|
@ -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"})
|
url = http.prepare_url("http://steamdb.info/calculator/", {"player": inp, "currency": currency if currency else "us"})
|
||||||
soup = http.get_soup(url)
|
soup = http.get_soup(url)
|
||||||
|
|
||||||
|
out = u""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
name = soup.findAll('h1', {'class': 'header-title'})[1].text
|
out += soup.findAll('h1', {'class': 'header-title'})[1].text.strip()
|
||||||
status = soup.findAll('td')[7].text
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print e
|
||||||
return u"\x02Unable to retrieve info for %s!\x02 Is it a valid SteamCommunity profile username (%s)? " \
|
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))
|
"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":
|
if status == "Online":
|
||||||
status = "\x033\x02Online\x02\x0f"
|
status = "\x033\x02Online\x02\x0f"
|
||||||
elif status == "Offline":
|
elif status == "Offline":
|
||||||
|
@ -75,41 +84,25 @@ def steamcalc(inp, nick='', db=None):
|
||||||
status = "\x035\x02Busy\x02\x0f"
|
status = "\x035\x02Busy\x02\x0f"
|
||||||
elif "Looking to" in status:
|
elif "Looking to" in status:
|
||||||
status = "\x036\x02%s\x02\x0f" % status
|
status = "\x036\x02%s\x02\x0f" % status
|
||||||
|
out += " (%s)" % status
|
||||||
|
|
||||||
out = ""
|
for i in soup.findAll('div', {'class': 'panel'}):
|
||||||
|
if str(i.find('div', {'class': 'panel-heading'})) == '<div class="panel-heading">Markdown</div>':
|
||||||
try:
|
data = i
|
||||||
twdata = soup.find('h1', {'class': 'header-title pull-right'}).find('a')['data-text'].split(", ")
|
data = data.findAll('p')[1:]
|
||||||
money = twdata[0].split("My #Steam account is worth ")[1]
|
money = data[0].text.split(" ")[-1]
|
||||||
time = twdata[1].split("and I spent ")[1].split(" playing games!")[0]
|
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)
|
out += " This account is worth \x02%s\x02, and they've spent \x02%s\x02 playing games! " % (money, time)
|
||||||
except:
|
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)
|
||||||
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
|
|
||||||
|
|
||||||
if not dontsave:
|
if not dontsave:
|
||||||
db.execute("insert or replace into steam(nick, acc) values (?,?)", (nick.lower(), inp))
|
db.execute("insert or replace into steam(nick, acc) values (?,?)", (nick.lower(), inp))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
if not out:
|
return out + web.try_isgd(url)
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
def get_steam_info(url):
|
def get_steam_info(url):
|
||||||
|
|
Reference in a new issue