diff options
author | Alexander Kabui | 2021-11-17 20:38:20 +0300 |
---|---|---|
committer | Alexander Kabui | 2021-11-17 20:38:20 +0300 |
commit | 1a3b85c4ebc66d54e3bda06c3742e8046e4c8159 (patch) | |
tree | d2ad66b18cfbd831f6a1cb1e18b5583598f05d78 | |
parent | 6786712e95cbb885b6b19b3ecd34e6c8ee893172 (diff) | |
download | genenetwork2-1a3b85c4ebc66d54e3bda06c3742e8046e4c8159.tar.gz |
add generic functio for generating filename
-rw-r--r-- | wqflask/wqflask/correlation/pre_computes.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/wqflask/wqflask/correlation/pre_computes.py b/wqflask/wqflask/correlation/pre_computes.py index 403d60c9..241b0730 100644 --- a/wqflask/wqflask/correlation/pre_computes.py +++ b/wqflask/wqflask/correlation/pre_computes.py @@ -13,8 +13,9 @@ def fetch_all_cached_metadata(dataset_name): file_path = os.path.join(TMPDIR, file_name) - with open(file_path, "r+") as file_handler: - dataset_metadata = json.load(file_handler) + try: + with open(file_path, "r+") as file_handler: + dataset_metadata = json.load(file_handler) except FileNotFoundError: Path(file_path).touch(exist_ok=True) @@ -32,6 +33,13 @@ def cache_new_traits_metadata(dataset_metadata: dict, new_traits_metadata, file_ json.dump(dataset_metadata, file_handler) +def generate_file_name(*args, prefix=""): + """given a list of args generate a unique filename""" + + string_unicode = f"{*args,}{prefix}".encode() + return hashlib.md5(string_unicode).hexdigest() + + def generate_filename(base_dataset_name, target_dataset_name, base_timestamp, target_dataset_timestamp): """generate unique filename""" |