Parcourir la source

Added option to export into sql query file

master
il y a 5 ans
Parent
révision
79c20f5b2f
  1. 21
      main.py

21
main.py

@ -82,6 +82,7 @@ def inserttodb(c, q, d): @@ -82,6 +82,7 @@ def inserttodb(c, q, d):
#------------------------------------------------+
# insert new data directly into new database file
def i(d, s):
con = sql.connect(d)
with con:
@ -102,6 +103,22 @@ def i(d, s): @@ -102,6 +103,22 @@ def i(d, s):
if con:
con.rollback()
# 'insert' new data into a file i.e sql query file
def f(d, s):
with open(d, 'w', encoding='utf-8') as h:
times, ranks, ids = filters(cleanup(readfile(s)))
for t in times:
h.write("INSERT OR REPLACE INTO Cts_times VALUES(%s, %s, %s, %s)\n" % tuple(t))
pass
for r in ranks:
h.write("INSERT OR REPLACE INTO Cts_ranks VALUES(%s, %s, %s, %s)\n" % tuple(r))
pass
for i in ids:
h.write("INSERT OR REPLACE INTO Id2aslias VALUES(%s, %s, %s)\n" % tuple(i))
pass
pass
pass
# Test whether repeat rows are added.
def duplicatestest(d, s):
c = sql.connect(d)
@ -146,9 +163,13 @@ if __name__ == "__main__": @@ -146,9 +163,13 @@ if __name__ == "__main__":
ap.add_argument('db')
ap.add_argument('src')
ap.add_argument('-t', '--test', action='store_true')
ap.add_argument('-q', '--sql', action='store_true')
args = ap.parse_args()
initl()
if args.test:
duplicatestest(args.db, args.src)
if args.sql:
f(args.db, args.src)
else:
i(args.db, args.src)

Chargement…
Annuler
Enregistrer