Guest User

Untitled

a guest
Jan 19th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. import os
  2. import time
  3. import mysql.connector
  4. from validate_email import validate_email
  5. import time
  6.  
  7. Server = mysql.connector.connect(host="127.0.0.1", user="root", passwd="root", db="pwdquery", port=8889)
  8. Cursor = Server.cursor()
  9.  
  10. # Get a list of files to read
  11. fileCount = 1
  12. for root, dirs, files in os.walk('/Volumes/dansku/tempDump/data'):
  13. for file in files:
  14.  
  15. #Let's not import emails starting with symbols
  16. if file != "symbols":
  17.  
  18. filePath = os.path.join(root, file)
  19.  
  20. #Open File
  21. f = open(filePath, "r")
  22.  
  23. #read all lines into a list
  24. emails = f.readlines()
  25.  
  26. for email in emails:
  27.  
  28.  
  29. emailError = False
  30.  
  31. try:
  32. email = email.replace(" ", "").replace(";",":").rstrip()
  33. emailAddress = email.split(":")[0]
  34. password = email.split(":")[1]
  35. password = password.replace('"', '\\"').replace("'", "\\'")
  36.  
  37. except:
  38. emailError = True
  39. print "ERROR WITH " + email
  40.  
  41. if validate_email(emailAddress) is True and emailError is False:
  42.  
  43. fileCount += 1
  44.  
  45. print str(fileCount) + " -> Saving: " + emailAddress + " : " + password
  46.  
  47. #CHECK IF EMAIL EXISTS
  48. Cursor.execute('''SELECT * FROM email WHERE email = "%s"''' % (emailAddress))
  49. userInfo = Cursor.fetchall()
  50.  
  51. # IF EMAIL EXISTS
  52. if len(userInfo) > 0:
  53. for user in userInfo:
  54. userID = user[0]
  55.  
  56. # NOT INSERT PASSWORD TWICE
  57. Cursor.execute('''SELECT * FROM password WHERE email_id = "%s" AND password = "%s"''' % (userID, password))
  58. passwordInfo = Cursor.fetchall()
  59.  
  60. # ONLY SAVE PASSWORD IF THAT PASSWORD AND USER_ID DOESNT EXIST
  61. if len(passwordInfo) == 0:
  62.  
  63. # IF EMAIL ALREADY IN DATABASE, ONLY SAVE PASSWORD
  64. Cursor.execute('''INSERT INTO password (email_id, password) values ("%d", "%s")''' % (userID, password))
  65. Server.commit()
  66.  
  67. else:
  68.  
  69. # IF EMAIL NOT IN DATABASE, ADD NEW EMAIL AND SAVE PASSWORD
  70. Cursor.execute('''INSERT INTO email (email) values ("%s")''' % (emailAddress))
  71. Server.commit()
  72.  
  73. Cursor.execute('''SELECT LAST_INSERT_ID()''')
  74. lastID = Cursor.fetchall()
  75.  
  76. # Get recent user ID
  77. for user in lastID:
  78. userID = user[0]
  79.  
  80. # Finally save password to user
  81. Cursor.execute('''INSERT INTO password (email_id, password) values ("%d", "%s")''' % (userID, password))
  82. Server.commit()
Add Comment
Please, Sign In to add comment