raptr.py
· 1.6 KiB · Python
Raw
# Raptr last-played info retriever
# For use with CloudBot (http://git.io/cbgit), although it'll also work as a Python module
# (from raptr import raptr; print raptr("blha303");)
# (after removing the 'from util' and '@hook.command' lines, and switching lines 19 and 20)
#
# This file (raptr.py) created by Steven Smith (blha303) 2013
# GPLv3 license (because CloudBot is GPL)
# http://opensource.org/licenses/GPL-3.0
#
# For a working example of this, join irc.esper.net #xD and ask blha303 for a demonstration of raptr.py
# Email raptr@blha303.com.au for any questions.
from util import hook, http, web
from bs4 import BeautifulSoup as Soup
@hook.command
def raptr(inp):
"""raptr <nickname> - Looks up raptr last-played info. WIP """
# soup = Soup(urllib2.urlopen("http://raptr.com/%s/games?sort_by=last_played" % inp).read())
soup = http.get_soup("http://raptr.com/%s/games?sort_by=last_played" % inp)
script = soup.findAll('script')[-5]
data = script.text.strip()[49:].replace("\\/", "/").replace('\\"', '"')
newsoup = Soup(data)
rank = newsoup.find('li', {'class': 'game-rank'}).find('span').text
if rank == "Elite":
rank = "\x037Elite\x0f"
elif rank == "Newbie":
rank = "\x0315Newbie\x0f"
elif rank == "Dedicated":
rank = "\x0312Dedicated\x0f"
elif rank == "Amateur":
rank = "\x0314Amateur\x0f"
return "%s last played %s. They have %s logged in that game (%s)." % (inp,
newsoup.find('a', {'class': 'game-title'}).text,
newsoup.find('li', {'class': 'game-hours'}).text.strip(),
rank)
| 1 | # Raptr last-played info retriever |
| 2 | # For use with CloudBot (http://git.io/cbgit), although it'll also work as a Python module |
| 3 | # (from raptr import raptr; print raptr("blha303");) |
| 4 | # (after removing the 'from util' and '@hook.command' lines, and switching lines 19 and 20) |
| 5 | # |
| 6 | # This file (raptr.py) created by Steven Smith (blha303) 2013 |
| 7 | # GPLv3 license (because CloudBot is GPL) |
| 8 | # http://opensource.org/licenses/GPL-3.0 |
| 9 | # |
| 10 | # For a working example of this, join irc.esper.net #xD and ask blha303 for a demonstration of raptr.py |
| 11 | # Email raptr@blha303.com.au for any questions. |
| 12 | |
| 13 | from util import hook, http, web |
| 14 | from bs4 import BeautifulSoup as Soup |
| 15 | |
| 16 | @hook.command |
| 17 | def raptr(inp): |
| 18 | """raptr <nickname> - Looks up raptr last-played info. WIP """ |
| 19 | # soup = Soup(urllib2.urlopen("http://raptr.com/%s/games?sort_by=last_played" % inp).read()) |
| 20 | soup = http.get_soup("http://raptr.com/%s/games?sort_by=last_played" % inp) |
| 21 | script = soup.findAll('script')[-5] |
| 22 | data = script.text.strip()[49:].replace("\\/", "/").replace('\\"', '"') |
| 23 | newsoup = Soup(data) |
| 24 | rank = newsoup.find('li', {'class': 'game-rank'}).find('span').text |
| 25 | if rank == "Elite": |
| 26 | rank = "\x037Elite\x0f" |
| 27 | elif rank == "Newbie": |
| 28 | rank = "\x0315Newbie\x0f" |
| 29 | elif rank == "Dedicated": |
| 30 | rank = "\x0312Dedicated\x0f" |
| 31 | elif rank == "Amateur": |
| 32 | rank = "\x0314Amateur\x0f" |
| 33 | return "%s last played %s. They have %s logged in that game (%s)." % (inp, |
| 34 | newsoup.find('a', {'class': 'game-title'}).text, |
| 35 | newsoup.find('li', {'class': 'game-hours'}).text.strip(), |
| 36 | rank) |
| 37 |