Hey everyone,
I have just started learning python and this is my first app (it's extremely small/basic/silly)
It's a text based linux admin (basically exactly the same to using telnet) but it's got text highlighting. (atm basic cause of my lack of knowledge on regexp)
I would like feedback and any help towards it.
Questions:
First time using threads, is it correct?
can anyone get player speech coloured?
#!/usr/bin/python
import socket, thread, re
def readSock():
while(1):
mess = mySocket.recv(1024)
if((mess.find('Time Left')!=-1) | (mess.find('Next map')!=-1) | (mess.find('File')!=-1)):
print '\033[37m' + mess + '\033[0m',
elif (re.match('\([0-9._%+-]\)', mess)):#Kills
print '\033[31m' + mess + '\033[0m',
#elif (re.match('\[[A-Z0-9._%+-]\]', mess)):#Player Speaking - Don't Know how to work it :(
#print '\033[35m' + mess + '\033[0m',
else:
print mess,
mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
host = raw_input('Host>> ')
port = int(raw_input('Port>> '))
pw = str(raw_input('Pass>> '))
mySocket.connect ( ( host, port ) )
mySocket.send ( pw + '\r\n' )
reply= mySocket.recv(1024)
if(reply.find('Invalid password.')!=-1):
print 'Couldn\'t Connect to Server'
exit();
print reply
thread.start_new_thread(readSock, ())
while(1) :
data = raw_input()
if not data:
break
else:
mySocket.send ( data + '\n')
mySocket.close()