revised function 'f' - gave better name, corrected output

This commit is contained in:
scuti 2024-10-28 23:10:54 -07:00
parent c956acbd4f
commit 3834385d2f

View File

@ -164,19 +164,19 @@ def i(d, s):
con.rollback() con.rollback()
# 'insert' new data into a file i.e sql query file # 'insert' new data into a file i.e sql query file
def f(d, s): def write_query(out_file, data):
with open(d, 'w', encoding='utf-8') as h: with open(out_file, 'w', encoding='utf-8') as file_handle:
times, ranks, ids, speed, speed_ids = filters(get_list_from_server_txt(s)) times, \
ranks, \
ids, \
speed, \
speed_ids = filters(get_list_from_server_txt(data))
for t in times: for t in times:
h.write("INSERT OR REPLACE INTO Cts_times VALUES(%s, %s, %s, %s)\n" % tuple(t)) file_handle.write("INSERT OR REPLACE INTO Cts_times VALUES(\'%s\', \'%s\', %s, %s);\n" % tuple(t))
pass
for r in ranks: for r in ranks:
h.write("INSERT OR REPLACE INTO Cts_ranks VALUES(%s, %s, %s, %s)\n" % tuple(r)) file_handle.write("INSERT OR REPLACE INTO Cts_ranks VALUES(\'%s\', \'%s\', %s, \'%s\');\n" % tuple(r))
pass
for i in ids: for i in ids:
h.write("INSERT OR REPLACE INTO Id2aslias VALUES(%s, %s, %s)\n" % tuple(i)) file_handle.write("INSERT OR REPLACE INTO Id2alias VALUES(\'%s\', \'%s\', \'%s\');\n" % tuple(i))
pass
pass
pass pass
# Test whether repeat rows are added. # Test whether repeat rows are added.
@ -237,9 +237,9 @@ if __name__ == "__main__":
duplicatestest(args.db, args.src) duplicatestest(args.db, args.src)
if args.query: if args.query:
try: try:
f(args.dest, args.src) write_query(args.dest, args.src)
except FileNotFoundError: except FileNotFoundError:
traceback.print_exc() traceback.print_exc()
print("\t Exiting - no file to work with.", file=sys.stderr) print("\n\t Exiting - no file to work with.", file=sys.stderr)
else: else:
i(args.dest, args.src) i(args.dest, args.src)