Привет люди ! Вот делаю бота для irc но не могу понять как мне выбрать информацию с def tpars(txt) , если знаете помогите =))
# -*- coding: cp1251 -*-
import socket
import time
import httplib
host='irc.lv'
channel='#Dragstyle^'
def tpars(txt):
q=txt.split('<span class="temp">') [1]
temp=q.split(' C') [0]
qq=txt.split('<span>') [1]
wind=qq.split('</span>') [0]
return temp
return wind
class parsing:
def __init__(self,DATA):
i=0
self.data = DATA
t=self.data.split('<TD>Players with 1 lvl</TD>') [0]
tt=t.split('<TD colSpan=3>Server</TD></TR>') [-1]
while i != 4:
num = str(i)
num=tt.split('</TD></TR>') [i]
info=num.split('<TD width=100>') [-1]
if i == 0:
acc = info
elif i == 1:
char = info
elif i == 2:
guild = info
elif i == 3:
online = info
i=i+1
self.debug = tt
self.acc = acc
self.online = online
self.char = char
self.guild = guild
def sendm(msg):
sock.send('PRIVMSG '+ channel + ' :' + str(msg) + '\r\n')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, 6667))
sock.send('USER python host servname : Python Bot\r\n')
sock.send('NICK pyMan\r\n')
while 1:
text=sock.recv(2040)
if not text:
break
if text.find('Message of the Day') != -1:
sock.send('JOIN '+ channel +'\r\n')
if text.find('PING') != -1:
sock.send('PONG ' + text.split() [1] + '\r\n')
if text.find(':!quit') != -1:
sock.send('QUIT :python bot\r\n')
if text.find(':bot') != -1:
sendm('no , you are bot')
if text.find('JOIN :'+ channel) != -1:
sendm('Hello')
if text.find(':KICK') != 1:
sock.send('JOIN '+ channel +'\r\n')
if text.find(':!status') != -1:
conn = httplib.HTTPConnection("mubass.oo.lv")
conn.request("GET","/?pg=serv-stats")
r = conn.getresponse()
data = r.read()
inf = parsing(data)
sendm('Online: '+ inf.online +'')
sendm('Accounts: '+ inf.acc +'')
sendm('Characters: '+ inf.char +'')
sendm('Guilds: '+ inf.guild +'')
conn.close()
if text.find(':!date') != -1:
sendm(''+ time.strftime("%A, %B %d, %Y", time.localtime()))
if text.find(':!time') != -1:
sendm(''+ time.strftime("%H:%M:%S", time.localtime()))
if text.find(':!weather') != -1:
c = httplib.HTTPConnection("www.1188.lv")
c.request("GET", "/laika_zinas/?city=Daugavpils")
ra = c.getresponse()
datas = ra.read()
tpars(datas)
sendm('Temp: '+ temp)
sendm('Wind: '+ wind)
c.close()
print '[GET]', text