From 8127c47f2d5c2ec7408cf652d3a46e1fe343ceb9 Mon Sep 17 00:00:00 2001 From: sebastiano bernuzzi <sebastiano.bernuzzi@gmail.com> Date: Wed, 6 Oct 2021 15:19:41 +0200 Subject: [PATCH] Added a separate example file for writing index for hybrids. Diff of the two coredb_write_index_json*.py file now highlights the changes. --- msc/coredb_clone_hybrid.py | 3 ++- msc/coredb_write_index_json.py | 6 +++--- msc/coredb_write_index_json_hybrid.py | 29 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 msc/coredb_write_index_json_hybrid.py diff --git a/msc/coredb_clone_hybrid.py b/msc/coredb_clone_hybrid.py index 30c2ef0..810e04f 100644 --- a/msc/coredb_clone_hybrid.py +++ b/msc/coredb_clone_hybrid.py @@ -6,10 +6,11 @@ FZ 09/2021 """ from watpy.coredb.coredb import * +import os # mkdirs -import os db_path = './CoRe_DB_clone/' os.makedirs(db_path, exist_ok=True) + cdb = CoRe_db(db_path, ifile = "json/DB_Hyb.json") idb = cdb.idb diff --git a/msc/coredb_write_index_json.py b/msc/coredb_write_index_json.py index 27b3514..926c453 100644 --- a/msc/coredb_write_index_json.py +++ b/msc/coredb_write_index_json.py @@ -6,10 +6,12 @@ SB 09/2021 """ from watpy.coredb.coredb import * +import os # mkdirs db_path = './CoRe_DB_clone/' +os.makedirs(db_path, exist_ok=True) + cdb = CoRe_db(db_path) -## cdb = CoRe_db(db_path, ifile = "json/DB_Hyb.json") #Use this for Hybrids! idb = cdb.idb # make sure the DB is up-to-date! @@ -25,5 +27,3 @@ idb.update_from_mdlist(mdlist) # write the index to JSON with the appropriate template idb.to_json_tmplk() -## idb.to_json_tmplk(tmpl = TXT_HYB) #Use this for Hybrids! - diff --git a/msc/coredb_write_index_json_hybrid.py b/msc/coredb_write_index_json_hybrid.py new file mode 100644 index 0000000..b16db29 --- /dev/null +++ b/msc/coredb_write_index_json_hybrid.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +""" +Write the index JSON from the metadata_main.txt in the DB +SB 09/2021 +""" + +from watpy.coredb.coredb import * +import os # mkdirs + +db_path = './CoRe_DB_clone/' +os.makedirs(db_path, exist_ok=True) + +cdb = CoRe_db(db_path, ifile = "json/DB_Hyb.json") #Use this for Hybrids! +idb = cdb.idb + +# make sure the DB is up-to-date! +cdb.sync() + +# read metadata_main in a list +mdlist = [] +for key in idb.dbkeys: + mdlist.append(cdb.sim[key].md) + +# update the index +idb.update_from_mdlist(mdlist) + +# write the index to JSON with the appropriate template +idb.to_json_tmplk(tmpl = TXT_HYB) #Use this for Hybrids! -- GitLab