mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
Changed format of gameknot URL snarfer.
This commit is contained in:
parent
7e5162d8e4
commit
94c10ca5da
@ -34,6 +34,7 @@ from baseplugin import *
|
|||||||
import re
|
import re
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
import debug
|
||||||
import ircmsgs
|
import ircmsgs
|
||||||
import ircutils
|
import ircutils
|
||||||
import ircutils
|
import ircutils
|
||||||
@ -62,25 +63,31 @@ class Forums(callbacks.PrivmsgRegexp):
|
|||||||
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
|
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
|
||||||
'That doesn\'t appear to be a proper Google Groups page.'))
|
'That doesn\'t appear to be a proper Google Groups page.'))
|
||||||
|
|
||||||
gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<")
|
_gkPlayer = re.compile(r"popd\('(Rating[^']+)'\).*?>([^<]+)<")
|
||||||
|
_gkRating = re.compile(r": (\d+)[^:]+:<br>(\d+)[^,]+, (\d+)[^,]+, (\d+)")
|
||||||
def gameknot(self, irc, msg, match):
|
def gameknot(self, irc, msg, match):
|
||||||
r"http://(?:www\.)?gameknot.com/chess.pl\?bd=\d+&r=\d+"
|
r"http://(?:www\.)?gameknot.com/chess.pl\?bd=\d+&r=\d+"
|
||||||
fd = urllib2.urlopen(match.group(0))
|
fd = urllib2.urlopen(match.group(0))
|
||||||
s = fd.read()
|
s = fd.read()
|
||||||
|
fd.close()
|
||||||
try:
|
try:
|
||||||
((wRating, wName), (bRating, bName)) = self.gkPlayer.findall(s)
|
((wRating, wName), (bRating, bName)) = self._gkPlayer.findall(s)
|
||||||
wName = ircutils.bold(wName)
|
wName = ircutils.bold(wName)
|
||||||
bName = ircutils.bold(bName)
|
bName = ircutils.bold(bName)
|
||||||
wRating = wRating.replace('<br>', ' ')
|
(wRating, wWins, wLosses, wDraws) = \
|
||||||
bRating = bRating.replace('<br>', ' ')
|
self._gkRating.search(wRating).groups()
|
||||||
wRating = wRating.replace('Wins', '; Wins')
|
(bRating, bWins, bLosses, bDraws) = \
|
||||||
bRating = bRating.replace('Wins', '; Wins ')
|
self._gkRating.search(bRating).groups()
|
||||||
|
wStats = '%s; W-%s, L-%s, D-%s' % (wRating, wWins, wLosses, wDraws)
|
||||||
|
bStats = '%s; W-%s, L-%s, D-%s' % (bRating, bWins, bLosses, bDraws)
|
||||||
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
|
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
|
||||||
'%s (%s) vs. %s (%s)' % (wName, wRating, bName, bRating)))
|
'%s (%s) vs. %s (%s)' % (wName, wStats, bName, bStats)))
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
|
irc.queueMsg(ircmsgs.privmsg(msg.args[0],
|
||||||
'That doesn\'t appear to be a proper Gameknot game.'))
|
'That doesn\'t appear to be a proper Gameknot game.'))
|
||||||
|
except Exception, e:
|
||||||
|
irc.error(msg, debug.exnToString(e))
|
||||||
|
|
||||||
|
|
||||||
Class = Forums
|
Class = Forums
|
||||||
|
Loading…
Reference in New Issue
Block a user