From 60e7b12addc3acc8b49ba6aa07b71ebcf6ddf54d Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Wed, 2 Apr 2025 15:31:58 +0800 Subject: Reverse download log lines and write them to a new file download_log_reversed.txt so that the most recent log line appears on the top. Purpose: easier to check log from the web browser. --- Code/download_and_map.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Code') diff --git a/Code/download_and_map.py b/Code/download_and_map.py index ebc742d..a78409e 100644 --- a/Code/download_and_map.py +++ b/Code/download_and_map.py @@ -361,6 +361,14 @@ def kill_process(process_name): print(f'{e}') return False +def reverse_lines(fname, fname2): + with open(fname) as f: + lines = f.readlines() + + with open(fname2, 'w') as f2: + lines.reverse() + content = ''.join(lines) + f2.write(content) ## main @@ -421,3 +429,4 @@ else: write_download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, '%s\n' % ('\n'.join(map_list))) write_download_log_file(DOWNLOADED_SRA_ID_LOG_FILE, 'DONE at %s\n' % (curr_time)) +reverse_lines(DOWNLOADED_SRA_ID_LOG_FILE, os.path.splitext(DOWNLOADED_SRA_ID_LOG_FILE)[0] + '_reversed.txt') -- cgit v1.2.1