Guest User

Untitled

a guest
Dec 14th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import pymysql.cursors
  2. #import mysql.connector
  3. #from mysql.connector import Error
  4.  
  5. class db_connection:
  6.  
  7. conn = ""
  8.  
  9. def __init__(self):
  10. #If using mysql driver
  11. #self.conn = mysql.connector.connect(host='192.168.20.248',
  12. #database='ow2mte',
  13. #user='root',
  14. #password='p!tmis88!')
  15.  
  16. #If using pymysql driver
  17. self.conn = pymysql.connect(host='192.168.20.248',
  18. user='root',
  19. password='p!tmis88!',
  20. db='ow2mte',
  21. charset='utf8mb4',
  22. cursorclass=pymysql.cursors.DictCursor)
  23.  
  24. def check_validity(self, stmt, params):
  25. cursor = self.conn.cursor()
  26. query = stmt
  27. cursor.execute(query, (params,))
  28. count = cursor.rowcount
  29.  
  30. return count
  31.  
  32. def disconnect(self):
  33. self.conn.close()
  34.  
  35. def inputNumber(message):
  36. while True:
  37. try:
  38. userEntry = int(input(message))
  39.  
  40. return userEntry
  41.  
  42. except ValueError:
  43. break
  44.  
  45. #MAIN CODE GOES AFTER THIS LINE
  46. while True:
  47. userInput = inputNumber("Please enter your user index: ")
  48.  
  49. if userInput:
  50. try:
  51. user_access = db_connection()
  52. is_valid = user_access.check_validity("Select ip_address From login_log Where user_index=%s Limit 0, 1", userInput)
  53. if is_valid > 0:
  54. print("It was a valid entry")
  55. else:
  56. print("Record not Found!")
  57. user_access.disconnect()
  58. except Error as e:
  59. continue
  60. elif userInput == 0000:
  61. break
  62. else:
  63. print("Empty/Invalid Entry! Please try again!")
Add Comment
Please, Sign In to add comment