Last active 1450585776

Raptr last-played lookup

Steven Smith revised this gist 1375552964. Go to revision

1 file changed, 2 insertions, 1 deletion

raptr.py

@@ -1,7 +1,7 @@
1 1 # Raptr last-played info retriever
2 2 # For use with CloudBot (http://git.io/cbgit), although it'll also work as a Python module
3 3 # (from raptr import raptr; print raptr("blha303");)
4 - # (after removing the 'from util' and '@hook.command' lines)
4 + # (after removing the 'from util' and '@hook.command' lines, and switching lines 19 and 20)
5 5 #
6 6 # This file (raptr.py) created by Steven Smith (blha303) 2013
7 7 # GPLv3 license (because CloudBot is GPL)
@@ -16,6 +16,7 @@ from bs4 import BeautifulSoup as Soup
16 16 @hook.command
17 17 def raptr(inp):
18 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())
19 20 soup = http.get_soup("http://raptr.com/%s/games?sort_by=last_played" % inp)
20 21 script = soup.findAll('script')[-5]
21 22 data = script.text.strip()[49:].replace("\\/", "/").replace('\\"', '"')

Steven Smith revised this gist 1375552242. Go to revision

1 file changed, 35 insertions

raptr.py(file created)

@@ -0,0 +1,35 @@
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)
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 = http.get_soup("http://raptr.com/%s/games?sort_by=last_played" % inp)
20 + script = soup.findAll('script')[-5]
21 + data = script.text.strip()[49:].replace("\\/", "/").replace('\\"', '"')
22 + newsoup = Soup(data)
23 + rank = newsoup.find('li', {'class': 'game-rank'}).find('span').text
24 + if rank == "Elite":
25 + rank = "\x037Elite\x0f"
26 + elif rank == "Newbie":
27 + rank = "\x0315Newbie\x0f"
28 + elif rank == "Dedicated":
29 + rank = "\x0312Dedicated\x0f"
30 + elif rank == "Amateur":
31 + rank = "\x0314Amateur\x0f"
32 + return "%s last played %s. They have %s logged in that game (%s)." % (inp,
33 + newsoup.find('a', {'class': 'game-title'}).text,
34 + newsoup.find('li', {'class': 'game-hours'}).text.strip(),
35 + rank)
Newer Older