dbinsert.py 386 B

123456789101112131415161718192021
  1. #!/usr/bin/env python3
  2. import sys
  3. import sqlite3
  4. if len(sys.argv) < 3:
  5. print("Usage: <database > <fortune file>")
  6. sys.exit(1)
  7. con = sqlite3.connect(sys.argv[1])
  8. cur = con.cursor()
  9. with open(sys.argv[2]) as fp:
  10. lines = fp.readlines()
  11. for line in lines:
  12. print(line)
  13. cur.execute("INSERT INTO mean VALUES (?)", (line,))
  14. con.commit()
  15. sys.exit(0)