Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pathlib
- import sqlite3
- import sys
- def get_records(dump_dir: str = '.'):
- for txt in pathlib.Path(dump_dir).glob('USA *.txt'):
- print(txt.as_posix())
- with txt.open('r', encoding='utf-8') as records:
- for record in records:
- try:
- (phone_no, user_id, fname, lname, gender, city1, city2, relationship, company,
- d1, d2, d3, email, _) = record.split(':')
- except ValueError:
- pass
- else:
- yield (phone_no, user_id, fname, lname, gender, city1, city2, relationship,
- company, f'{d1}:{d2}:{d3}', email)
- if __name__ == '__main__':
- _, dst = sys.argv
- db = sqlite3.connect(dst)
- db.execute('PRAGMA synchronous = OFF;')
- db.execute('PRAGMA journal_mode = MEMORY;')
- db.execute('PRAGMA secure_delete = OFF;')
- db.execute('PRAGMA locking_mode = EXCLUSIVE;')
- db.isolation_level = None
- db.execute('''CREATE TABLE IF NOT EXISTS usa(phone_no, user_id, fname,
- lname, gender, city1, city2, relationship, company, seen,
- email);''')
- db.commit()
- db.executemany('INSERT INTO usa VALUES (?,?,?,?,?,?,?,?,?,?,?);', get_records())
- db.commit()
Advertisement
Add Comment
Please, Sign In to add comment