Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.39 KB | None | 0 0
  1. import socket
  2. import threading
  3. import time
  4. import logging
  5. import datetime
  6.  
  7. #Made by MegaLoler
  8.  
  9. HOST = '72.172.232.90'
  10. PORT = 443
  11.  
  12. USER = raw_input("Username: ")
  13. PASS = raw_input("Password: ")
  14. ROOM = raw_input("Room: ")
  15.  
  16. running = 1
  17.  
  18. s = None
  19.  
  20. class IdleThread (threading.Thread):
  21.     def run(self):
  22.         while running:
  23.             time.sleep(30)
  24.             if running:
  25.                 s.send(chr(13) + chr(10) + chr(0))                        
  26.  
  27. print "Connecting..."
  28. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  29. s.connect((HOST, PORT))
  30. s.send("v" + chr(0))
  31. data = s.recv(1024)
  32. print "Connected!"
  33. print "Logging in..."
  34. s.send("bauth:"+ROOM+":7202053138505182:"+USER+":"+PASS + chr(0))
  35. print "Logged in!"
  36. IdleThread().start()
  37. print "Preparing log file..."
  38. PATH = raw_input("Enter path to the directory to store the log file: ")
  39. logging.basicConfig(filename=PATH+"/chatango.log",level=logging.INFO)
  40. print "Logging has begun"
  41. while running:
  42.     data = s.recv(1024)
  43.     MES = ""
  44.     if data[0] == "b":
  45.         aa = data.split(":")
  46.         an = aa[2]
  47.         am = ":".join(aa[9:len(aa)])
  48.         am = am[0:len(am)-3]
  49.         n = am.count("<n")
  50.         nc = "default"
  51.         if n > 0:
  52.             nc = "#" + am[2:5]
  53.             am = am[7:len(am)]
  54.         MES = MES + "[namecolor=" + nc + "/]" + an + ": "
  55.         styles = am.split("<f ")
  56.         for st in styles:
  57.             if st == '':
  58.                 continue
  59.             pos = st.split(">")
  60.             std = pos[0]
  61.             st = ">".join(pos[1:len(pos)])
  62.             std = std.split('="')
  63.             d1 = std[0][1:len(std[0])]
  64.             d2 = std[1][0:len(std[1])-1]
  65.             siz = "10"
  66.             col = "#000"
  67.             fon = d2
  68.             if len(d1) == 2:
  69.                 siz = int(d1)
  70.             elif len(d1) == 3:
  71.                 col = "#" + d1
  72.             elif len(d1) == 5:
  73.                 siz = int(d1[0:2])
  74.                 col = "#" + d1[2:5]
  75.             elif len(d1) == 6:
  76.                 col = "#" + d1
  77.             elif len(d1) == 8:
  78.                 siz = int(d1[0:2])
  79.                 col = "#" + d1[2:8]
  80.             st = "".join(st.split("</f>"))
  81.             if st.count("<") > 0:
  82.                 B = 0
  83.                 U = 0
  84.                 I = 0
  85.                 st2 = st.split("<")
  86.                 for st in st2:
  87.                     if st == '':
  88.                         continue
  89.                     op = ""
  90.                     if st[1] == ">":
  91.                         if st[0].lower() == "b":
  92.                             B = B + 1
  93.                         if st[0].lower() == "u":
  94.                             U = U + 1
  95.                         if st[0].lower() == "i":
  96.                              I = I + 1
  97.                         st = st[2:len(st)]
  98.                     elif st[0] == "/" and st[2] == ">":
  99.                         if st[1].lower() == "b":
  100.                             B = B - 1
  101.                         if st[1].lower() == "u":
  102.                             U = U - 1
  103.                         if st[1].lower() == "i":
  104.                             I = I - 1
  105.                         st = st[3:len(st)]
  106.                     if st == '':
  107.                         continue
  108.                     if B or U or I:
  109.                         B2 = B
  110.                         U2 = U
  111.                         I2 = I
  112.                         if B2 > 1: B2 = 1
  113.                         if U2 > 1: U2 = 1
  114.                         if I2 > 1: I2 = 1
  115.                         bt = (""," bold, ")[B2]
  116.                         ut = (""," underline, ")[U2]
  117.                         it = (""," italic, ")[I2]
  118.                         op = "," + bt + ut + it
  119.                     st = st.replace(""","\"")
  120.                    st = st.replace("&apos;","'")
  121.                    st = st.replace(">",">")
  122.                    st = st.replace("<","<")
  123.                    MES = MES + "[style font=" + str(fon) + ", size=" + str(siz) + op + "]" + str(st) + "[/style]"
  124.            else:
  125.                st = st.replace(""","\"")
  126.                 st = st.replace("&apos;","'")
  127.                 st = st.replace(">",">")
  128.                 st = st.replace("<","<")
  129.                 MES = MES + "[style font=" + str(fon) + ", size=" + str(siz) + "]" + str(st) + "[/style]"
  130.     if MES != "":
  131.         now = str(datetime.datetime.now())
  132.         MES = now + ": " + MES
  133.         print MES
  134.         logging.info(MES + "\n")
  135.  
  136. s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement