coding utf-8 from processor import Processor from decorators import si

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
from processor import Processor
from decorators import simple_named_processor
from message import Message
from random import randint
import urllib2
import re
from time import time
class iBashorgRuProcessor(Processor):
protocol = 'all' #protocol name
lowLevel = 0 # 1 if lowlevel for protocol
help = '!bash [#num] - get bash quote (number #num) or random'
serv = 'http://ibash.org.ru';
path = '/quote.php?id=%s';
@simple_named_processor('ibash')
def process(self, frm, text):
if not text:
path = '/random.php'
else:
num = text
path = self.path % str(num)
res = urllib2.urlopen(self.serv + path).read().decode('cp1251')
pattern_number = re.compile('<a href="/quote.php?id=(\d+)&amp;vote=minus" onclick="[^"]">–</a></span></div>',re.S)
pattern_body = re.compile('<div class="quotbody">(.*?)</div>', re.S)
res_numer = pattern_nember.search(res)
res_body = pattern_body.search(res)
if res:
res = "#" + res_number.groups()[0] + ":\n" + res_body.groups()[0].replace('<br>','\n').replace('<br/>','\n').replace('<br />','\n').replace('&lt;','<').replace('&gt;','>').replace('&quot;','"')
else:
res = 'No such quote'