Skip to content

Commit 5c021e0

Browse files
committed
Add SC2 plugin
0 parents  commit 5c021e0

File tree

8 files changed

+177
-0
lines changed

8 files changed

+177
-0
lines changed

SC2/__init__.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
###
2+
# Copyright (c) 2005, James Vega
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
###
29+
30+
"""
31+
Performs various stock-related commands. Currently, this only retrieves
32+
stockquotes.
33+
"""
34+
35+
import supybot
36+
import supybot.world as world
37+
38+
# Use this for the version of this plugin. You may wish to put a CVS keyword
39+
# in here if you're keeping the plugin in CVS or some similar system.
40+
__version__ = ""
41+
42+
__author__ = "Simen Graaten"
43+
44+
# This is a dictionary mapping supybot.Author instances to lists of
45+
# contributions.
46+
__contributors__ = {}
47+
48+
# This is a url where the most recent plugin package can be downloaded.
49+
__url__ = '' # 'http://supybot.com/Members/yourname/Stock/download'
50+
51+
import config
52+
import plugin
53+
reload(plugin) # In case we're being reloaded.
54+
# Add more reloads here if you add third-party modules and want them to be
55+
# reloaded when this plugin is reloaded. Don't forget to import them as well!
56+
57+
if world.testing:
58+
import test
59+
60+
Class = plugin.Class
61+
configure = config.configure
62+
63+
64+
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

SC2/__init__.pyc

595 Bytes
Binary file not shown.

SC2/config.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
###
2+
# Copyright (c) 2005, James Vega
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
###
29+
30+
import supybot.conf as conf
31+
import supybot.registry as registry
32+
33+
def configure(advanced):
34+
# This will be called by supybot to configure this module. advanced is
35+
# a bool that specifies whether the user identified himself as an advanced
36+
# user or not. You should effect your configuration by manipulating the
37+
# registry as appropriate.
38+
from supybot.questions import expect, anything, something, yn
39+
conf.registerPlugin('SC2', True)
40+
41+
42+
Stock = conf.registerPlugin('SC2')
43+
# This is where your configuration variables (if any) should go. For example:
44+
# conf.registerGlobalValue(Stock, 'someConfigVariableName',
45+
# registry.Boolean(False, """Help for someConfigVariableName."""))
46+
47+
48+
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

SC2/config.pyc

604 Bytes
Binary file not shown.

SC2/dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"achievement_points":415,"teams":[{"points":0,"division_id":19234,"wins":2,"is_random":false,"division_rank":72,"losses":3,"division":"Division Grizzly Foxtrot","bracket":2,"league":"bronze","ratio":"0.40","fav_race":"protoss"},{"points":0,"division_id":17816,"wins":3,"is_random":false,"division_rank":58,"losses":3,"division":"Division Tyrador Alamo","bracket":3,"league":"bronze","ratio":"0.50","fav_race":"protoss"},{"points":50,"division_id":15954,"wins":3,"is_random":false,"division_rank":33,"losses":7,"division":"Division Horner Rho","bracket":4,"league":"bronze","ratio":"0.30","fav_race":"protoss"},{"points":24,"division_id":11758,"wins":3,"is_random":false,"division_rank":63,"losses":3,"division":"Division Akilae Tango","bracket":3,"league":"bronze","ratio":"0.50","fav_race":"protoss"}],"updated_at":"2010-08-17T20:54:34Z","character_code":658,"id":750940,"bnet_id":882437}

SC2/plugin.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import supybot.utils as utils
2+
from supybot.commands import *
3+
import supybot.callbacks as callbacks
4+
import sys
5+
import urllib
6+
import json
7+
8+
class SC2(callbacks.Plugin):
9+
def __init__(self, irc):
10+
callbacks.Plugin.__init__(self, irc)
11+
self.errorReported = False
12+
13+
def sc(self, irc, msg, args, name, charcode):
14+
"""<name> <charcode>
15+
16+
Show sc2 ranks for a character
17+
"""
18+
19+
colors = range(3, 16)
20+
21+
try:
22+
url = "http://sc2ranks.com/api/char/eu/%s$%s" % (name, charcode)
23+
d = urllib.urlopen(url).read()
24+
except IOError, i:
25+
if self.errorReported == False:
26+
irc.reply("SC2Ranks.com seems to be down checking for %s" % (url))
27+
self.errorReported = True
28+
return
29+
30+
self.errorReported = False
31+
32+
js = json.loads(d)
33+
34+
if len(js) > 0:
35+
string = u''
36+
37+
bnet_id = unicode(js['bnet_id'])
38+
string += 'http://eu.battle.net/sc2/en/profile/%s/1/%s/ ' % (bnet_id, name)
39+
i = 0
40+
for t in js['teams']:
41+
string += "\x03%s" % ( colors[t['bracket']] )
42+
string += "[%sv%s] %s/%s [%s] %spt %s #%s " % ( t['bracket'], t['bracket'], t['wins'], t['losses'], t['league'], t['points'], t['division'], t['division_rank'] )
43+
string += "\x03"
44+
i +=1
45+
46+
irc.reply(string.encode("UTF-8"))
47+
48+
sc = wrap(sc, ['something', 'something'])
49+
50+
51+
Class = SC2
52+

SC2/plugin.pyc

1.93 KB
Binary file not shown.

SC2/test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from urllib2 import urlopen
2+
import json
3+
4+
#d = urlopen("http://sc2ranks.com/api/char/eu/Yggdar$658").read()
5+
d = open("dump").read()
6+
7+
js = json.loads(d)
8+
9+
bnet_id = unicode(js['bnet_id'])
10+
for t in js['teams']:
11+
print "[%sv%s] %s/%s [%s] %3spt %s #%s" % ( t['bracket'], t['bracket'], t['wins'], t['losses'], t['league'], t['points'], t['division'], t['division_rank'] )
12+

0 commit comments

Comments
 (0)