Advertisement
Guest User

mysqltest

a guest
Feb 15th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.25 KB | None | 0 0
  1. import mysql.connector
  2. import random
  3. from time import sleep
  4. def splitText(string, symbol):
  5.     text=[]
  6.     word=""
  7.     for i in string:
  8.         if i == symbol:
  9.             wordn = deleteNewLine(word)
  10.             text.append(wordn)
  11.             word = ""
  12.         else:
  13.             word+=i
  14.     wordn = deleteNewLine(word)
  15.     text.append(wordn)
  16.     return text
  17. def splitSymbols(string):
  18.     symbols = []
  19.     for i in string:
  20.         symbols.append(i)
  21.     return symbols
  22. def deleteNewLine(string):
  23.     word=""
  24.     for i in string:
  25.         if i != "\n":
  26.             word+=i
  27.     return word
  28. cnx = mysql.connector.connect(host='mysql.v62-000.myjino.ru',database='v62-000',unix_socket='/var/lib/mysql/mysql.sock',user='v62-000',password='qwerty')
  29. cursor = cnx.cursor()
  30. go = 0
  31. lastid=0
  32. IDLAST = 0
  33. while go == 0:
  34.     quary = ("SELECT * FROM  `message` ORDER BY  `time` DESC LIMIT 0 , 1")
  35.     cursor.execute(quary)
  36.     messages = []
  37.     first = 0
  38.     for (ID,message,time) in cursor:
  39.        
  40.         text = str(ID)+":"+message
  41.         messages.append(text)
  42.         if first == 0:
  43.             IDLAST = ID
  44.             first = 1
  45.     for i in messages:
  46.         text = splitText(i,":")
  47.        
  48.         if text[2] == "/fuckyougod":
  49.             if lastid!=text[0]:
  50.                 print("HEY")
  51.                 print(lastid)
  52.                 lastid = text[0]
  53.                 nid = 0
  54.                 if IDLAST!=30:
  55.                     nid = IDLAST+1
  56.                 else:
  57.                     nid = 1
  58.                 print(nid)
  59.                 query = ("REPLACE INTO `message` (id, message) VALUES ('"+str(nid)+"','GOD:FUCK YOU')")
  60.                 cursor.execute(query)
  61.                 cnx.commit()
  62.         elif text[2] == "/gif":
  63.             if lastid!=text[0]:
  64.                 print("HEY")
  65.                 print(lastid)
  66.                 lastid = text[0]
  67.                 nid = 0
  68.                 if IDLAST!=30:
  69.                     nid = IDLAST+1
  70.                 else:
  71.                     nid = 1
  72.                 print(nid)
  73.                
  74.                 gifs=["http://0.media.dorkly.cvcdn.com/20/73/90d144c119251889319ebc533f7ba0bb.gif","https://media.giphy.com/media/10E0y3sVPdnGus/giphy.gif","http://1.media.dorkly.cvcdn.com/57/59/e93a657eec2d90205425e2c637e01f7f.gif","https://lh6.googleusercontent.com/-gghUt15LTsk/VQxKKVeM_7I/AAAAAAAAAZ8/asFUodR-U_8/w506-h910/GIF-Anime.gif","http://i.imgur.com/DHXa3ze.gif","https://s-media-cache-ak0.pinimg.com/originals/9e/58/98/9e589811edb61043b601d3186c7d212f.gif","http://media0.giphy.com/media/7u6Lr6c6ZIOqY/giphy.gif","https://s-media-cache-ak0.pinimg.com/originals/0a/83/77/0a8377fd7a9c9e52b32bca577cb25af6.gif","https://media.giphy.com/media/lvIBgQpJMPd7i/giphy.gif","http://media0.giphy.com/media/JG4iKdJamPHNK/giphy.gif","https://media.giphy.com/media/13LQZoCE0Nysr6/giphy.gif","https://media.giphy.com/media/xMpMPElKhAvgQ/giphy.gif","https://media.giphy.com/media/GhmvdoKizbEyc/giphy.gif"]
  75.                 num = random.randint(0, len(gifs)-1)
  76.                 query = ("REPLACE INTO `message` (id, message) VALUES ('"+str(nid)+"','<img src="'"'+gifs[num]+'"'">')")
  77.                 cursor.execute(query)
  78.                 cnx.commit()
  79.         if text[2] == "HELLO GOD":
  80.             if lastid!=text[0]:
  81.                 print("HEY")
  82.                 print(lastid)
  83.                 lastid = text[0]
  84.                 nid = 0
  85.                 if IDLAST!=30:
  86.                     nid = IDLAST+1
  87.                 else:
  88.                     nid = 1
  89.                 print(nid)
  90.                 query = ("REPLACE INTO `message` (id, message) VALUES ('"+str(nid)+"','GOD:HELLO, "+text[1]+". I am your father.')")
  91.                 cursor.execute(query)
  92.                 cnx.commit()
  93.         if text[1] == "Echo":
  94.             if lastid!=text[0]:
  95.                 print("HEY")
  96.                 print(lastid)
  97.                 lastid = text[0]
  98.                 nid = 0
  99.                 if IDLAST!=30:
  100.                     nid = IDLAST+1
  101.                 else:
  102.                     nid = 1
  103.                 print(nid)
  104.                 query = ("REPLACE INTO `message` (id, message) VALUES ('"+str(nid)+"','People:The Great Echo! We love you Echo!')")
  105.                 cursor.execute(query)
  106.                 cnx.commit()
  107.     sleep(1)
  108. cursor.close()
  109. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement