diff options
author | Hui Lan <lanhui@zjnu.edu.cn> | 2024-08-05 14:44:44 +0800 |
---|---|---|
committer | Hui Lan <lanhui@zjnu.edu.cn> | 2024-08-05 14:44:44 +0800 |
commit | df4af8751a5c1e1465159083100b82e58e7778f7 (patch) | |
tree | 4962f84f789520f3e3be54e94ff11f06d5e35e8f /Code/update_network_by_force.py | |
parent | 0d5e23b870ef9fa21cc90e31150dc1c27d56b3f8 (diff) |
Update write_log_file() so that it put the most recent message on the top; remove duplicate write_log_file()
Diffstat (limited to 'Code/update_network_by_force.py')
-rw-r--r-- | Code/update_network_by_force.py | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/Code/update_network_by_force.py b/Code/update_network_by_force.py index 079f677..fae2965 100644 --- a/Code/update_network_by_force.py +++ b/Code/update_network_by_force.py @@ -1,8 +1,9 @@ # Usage: python3 update_network_by_force.py -# Purpose: update_network.py could take a few days (even weeks) to run. Run this script to harvest new edges everyday. +# Purpose: update_network.py could take a few days (even weeks) to run. Run this script to harvest new edges before update_network.py finishes. # # Revision history: -# Last modified: 24 Nov 2019, hui <lanhui@zjnu.edu.cn> +# 24 Nov 2019, hui <lanhui@zjnu.edu.cn> +# Last modified: 5 Aug 2024, hui <lanhui@zjnu.edu.cn> import os, sys import glob @@ -12,21 +13,11 @@ from configure import HISTORY_DIR, HISTORY_DIR2, UPDATE_NETWORK_LOG_FILE, MERGED from configure import PARAMETER_FOR_BUILDCMATRIX, PARAMETER_FOR_BUILDRMATRIX, PARAMETER_FOR_NET from configure import DIFF_EDGE_FILE from backup_files import copy_and_backup_file +from log import write_log_file from overlap import Overlap import utils ########## Helper functions ####################### -def write_log_file(s, fname): - f = open(fname, 'a') - curr_time = datetime.now().strftime('%Y-%m-%d %H:%M') - s = '[' + curr_time + ']: ' + s - if not '\n' in s: - s += '\n' - f.write(s) - f.close() - print('Log: %s' % (s.strip())) - - def num_line(fname): ''' Return number of lines in file fname. ''' if not os.path.exists(fname): @@ -52,6 +43,7 @@ def age_of_file_in_seconds(fname): seconds = time.time() - st.st_mtime return seconds + def concatenate_edge_files(fname_lst, dir_out, fname_out): fout = open(os.path.join(dir_out, fname_out), 'w') for fname in fname_lst: @@ -78,7 +70,7 @@ def concatenate_edge_files(fname_lst, dir_out, fname_out): else: write_log_file('[update_network_by_force.py] In function concatenate_edge_files(). Check file %s. It has no rows with 10 fields.' % (fname), UPDATE_NETWORK_LOG_FILE) fout.close() - + def delete_edge_files(fname_lst): age_in_hours = 6 |