Advertisement
Guest User

Untitled

a guest
Dec 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS users (" +
  2. "vk_id int(11) NOT NULL," +
  3. "group int(11) NOT NULL, " +
  4. "curr_path varchar(255) NOT NULL,"
  5. "karma int(11) NOT NULL, " +
  6. "PRIMARY KEY (vk_id)"
  7. ") DEFAULT CHARSET=utf8;")
  8.  
  9. self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS subjects (" +
  10. "id int AUTO_INCREMENT, "
  11. "name varchar(255) NOT NULL, " +
  12. "PRIMARY KEY (id)"
  13. ") DEFAULT CHARSET=utf8;")
  14.  
  15. self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS points (" +
  16. "vk_id int NOT NULL, " +
  17. "subject_id int NOT NULL, "
  18. "value int NOT NULL"
  19. ") DEFAULT CHARSET=utf8;")
  20.  
  21.  
  22. import mysql.connector
  23. import traceback
  24.  
  25.  
  26. class DB:
  27. def __init__(self):
  28. self.botDB = mysql.connector.connect(host="localhost", user="breezequeue", password="8C9v87FTTHsMw9b6",
  29. db="breezequeue",
  30. charset="utf8")
  31. self.botDB.autocommit = True
  32. self.botDBCursor = self.botDB.cursor(buffered=True)
  33.  
  34. self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS users (" +
  35. "vk_id int(11) NOT NULL," +
  36. "group int(11) NOT NULL, " +
  37. "curr_path varchar(255) NOT NULL,"
  38. "karma int(11) NOT NULL, " +
  39. "PRIMARY KEY (vk_id)"
  40. ") DEFAULT CHARSET=utf8;")
  41.  
  42. self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS subjects (" +
  43. "id int AUTO_INCREMENT, "
  44. "name varchar(255) NOT NULL, " +
  45. "PRIMARY KEY (id)"
  46. ") DEFAULT CHARSET=utf8;")
  47.  
  48. self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS points (" +
  49. "vk_id int NOT NULL, " +
  50. "subject_id int NOT NULL, "
  51. "value int NOT NULL"
  52. ") DEFAULT CHARSET=utf8;")
  53.  
  54. def updateUser(self, user):
  55. self.botDBCursor.execute("UPDATE users SET curr_path = %s WHERE vk_id = %s;", (user.currPath, user.vkId))
  56. self.botDB.commit()
  57.  
  58. def getAllUsers(self):
  59. self.botDBCursor.execute("SELECT vk_id, curr_path FROM users")
  60. return self.botDBCursor.fetchall()
  61.  
  62. def getSubjects(self):
  63. self.botDBCursor.execute("SELECT id, name FROM subjects;")
  64. return self.botDBCursor.fetchall()
  65.  
  66. def addPointsToUser(self, user, subjectId, points):
  67. self.botDBCursor.execute("UPDATE points SET points = points + %s WHERE subject_id = %s AND vk_id = %s", (points, subjectId, user.vkId))
  68. self.botDB.commit()
  69.  
  70. def close(self):
  71. self.botDB.close()
  72.  
  73.  
  74. import arg_parser
  75.  
  76.  
  77. def handle(user, req, db):
  78. res = db.siteDBCursor.fetchone()
  79. if not res:
  80. user.writeMsg("Тебя не нашли в базе")
  81. return "index.json" # перенаправление в главное меню
  82.  
  83. db.addPointsToUser(user, 1, 10) # добавить 10 баллов юзеру на 1-й предмет
  84. if not user.args.requireArg("name", "Введи логин:", confirmationRequired=False,
  85. isOptional=False): # потребовать логин
  86. return
  87.  
  88. # если управление перешло сюда - значит юзер ввел логин успешно
  89.  
  90. userName = user.args.getArgValueByKey("name") # получить аргумент, который ты потребовал(-а)
  91. db.addPointsToUser(user, 1, 10) # добавить 10 баллов юзеру на 1-й предмет
  92.  
  93. user.writeMsg("FSDFDSFDS пРИВЕТ! \n")
  94.  
  95.  
  96. if not res:
  97. arg_parser.clearUserArgs(user) # очистить кэш аргументов
  98. return "index.json"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement