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()
# '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, speed, speed_ids = filters(get_list_from_server_txt(s))
def write_query(out_file, data):
with open(out_file, 'w', encoding='utf-8') as file_handle:
times, \
ranks, \
ids, \
speed, \
speed_ids = filters(get_list_from_server_txt(data))
for t in times:
h.write("INSERT OR REPLACE INTO Cts_times VALUES(%s, %s, %s, %s)\n" % tuple(t))
pass
file_handle.write("INSERT OR REPLACE INTO Cts_times VALUES(\'%s\', \'%s\', %s, %s);\n" % tuple(t))
for r in ranks:
h.write("INSERT OR REPLACE INTO Cts_ranks VALUES(%s, %s, %s, %s)\n" % tuple(r))
pass
file_handle.write("INSERT OR REPLACE INTO Cts_ranks VALUES(\'%s\', \'%s\', %s, \'%s\');\n" % tuple(r))
for i in ids:
h.write("INSERT OR REPLACE INTO Id2aslias VALUES(%s, %s, %s)\n" % tuple(i))
pass
pass
file_handle.write("INSERT OR REPLACE INTO Id2alias VALUES(\'%s\', \'%s\', \'%s\');\n" % tuple(i))
pass
# Test whether repeat rows are added.
@ -237,9 +237,9 @@ if __name__ == "__main__":
duplicatestest(args.db, args.src)
if args.query:
try:
f(args.dest, args.src)
write_query(args.dest, args.src)
except FileNotFoundError:
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:
i(args.dest, args.src)