Guest User

Untitled

a guest
Jan 1st, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. def isNewUser(msg):
  2. status = False
  3. try:
  4. mysql_info.debug('Подключение к базе')
  5. connection = pymysql.connect(
  6. host = config.mysql_host,
  7. user = config.mysql_user,
  8. password = config.mysql_password,
  9. db = config.mysql_db,
  10. charset = 'utf8mb4',
  11. cursorclass = pymysql.cursors.DictCursor,
  12. autocommit = True
  13. )
  14. mysql_info.debug('Подключение успешно')
  15. with connection.cursor as cursor:
  16. mysql_info.debug('Поиск пользователя в базе')
  17. findUserSQL = 'SELECT * FROM players WHERE userID = {}'.format(msg.chat.id)
  18. cursor.execute(findUserSQL)
  19. findUserSQLResult = cursor.fetchone()
  20. if findUserSQLResult == None:
  21. mysql_info.debug('Пользователь не найден. Регистрация')
  22. status = True
  23. currTime = curr_time_db()
  24. addUserSQL = 'INSERT INTO users (userID, username) VALUES ("{}","{}")'.format(msg.chat.id, msg.from_user.username)
  25. cursor.execute(addUserSQL)
  26. except Exception as e:
  27. logging.exception('Error: ')
  28. finally:
  29. mysql_info.debug('Закрытие соединения')
  30. connection.close()
  31. mysql_info.debug('Соединение закрыто')
  32. return status
Add Comment
Please, Sign In to add comment