Guest User

Untitled

a guest
Apr 3rd, 2021
4,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import sqlite3
  2. import os
  3. db = sqlite3.connect("fb_data_dump.db")
  4. db.execute('PRAGMA synchronous = OFF;')
  5. db.execute('PRAGMA journal_mode = MEMORY;')
  6. db.execute('PRAGMA secure_delete = OFF;')
  7. db.execute('PRAGMA locking_mode = EXCLUSIVE;')
  8. db.isolation_level = None
  9. db.execute("""
  10. CREATE TABLE IF NOT EXISTS
  11. usa(
  12. phone_no, user_id, fname, lname,
  13. gender, city1, city2, relationship,
  14. company, seen, email
  15. );
  16. """)
  17. insert_sql = "INSERT INTO usa VALUES (?,?,?,?,?,?,?,?,?,?,?);"
  18. db.commit()
  19. for cur in os.listdir("."):
  20. if cur.startswith("USA") and cur.endswith(".txt"):
  21. todo = []
  22. with open(cur, encoding="utf-8") as f:
  23. for row in f:
  24. row = row.split(":")
  25. if len(row) == 14:
  26. (
  27. phone_no, user_id, fname, lname, gender, city1, city2,
  28. relationship, company, d1, d2, d3, email, _) = row
  29. seen = d1 + ":" + d2 + ":" + d3
  30. todo.append((
  31. phone_no, user_id, fname, lname, gender,
  32. city1, city2, relationship, company, seen, email))
  33. if len(todo) > 1000000:
  34. print("insert", cur, todo[0])
  35. db.executemany(insert_sql, todo)
  36. db.commit()
  37. todo = []
  38. if len(todo) > 0:
  39. print("insert", cur, todo[0])
  40. db.executemany(insert_sql, todo)
  41. db.commit()
  42.  
Advertisement
Add Comment
Please, Sign In to add comment