From 79c20f5b2f8479a51d3ffce1027d3d486dd8c5cf Mon Sep 17 00:00:00 2001 From: <> Date: Tue, 12 Sep 2017 01:07:49 -0700 Subject: [PATCH] Added option to export into sql query file --- main.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.py b/main.py index 04ef55c..8fb07bb 100644 --- a/main.py +++ b/main.py @@ -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): 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__": 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) +