File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,11 +25,10 @@ def make_json_list(basedir:str):
2525 print (f"Error. Ensure root directory is oneAPI-samples repo. \n : { e } " )
2626
2727def merge_json_files (filepaths :list ):
28- '''Create pre-prod database from merged sample.json files from list of filenames '''
28+ '''From a list of filenames, output as json a pre-prod database of all sample.json files'''
2929 results_list = []
3030 try :
3131 for f in filepaths :
32- print (f )
3332 with open (f , 'r' ) as infile :
3433 results_list .append (json .load (infile ))
3534 # print(results_list)
@@ -85,13 +84,21 @@ def df_to_db(file_paths:list):
8584 db = df .to_json (rev_json , orient = 'records' )
8685 return db
8786
87+ def count_json_recs (filename :str ):
88+ try :
89+ with open (filename ) as f :
90+ db = json .load (f )
91+ print ("TOTAL RECORDS:" ,len (db ))
92+ except Exception as e :
93+ print (f"{ filename } not found. \n { e } " )
94+
8895def main ():
8996 '''Orchestrate sequence of steps to output sample_db_prd.json'''
9097 rootdir = sys .argv [- 1 ]
9198 file_paths = make_json_list (rootdir )
9299 merge_json_files (file_paths )
93100 json_db = df_to_db (file_paths )
94-
101+ count_json_recs ( "docs/_static/sample_db_prd.json" )
95102 return json_db
96103
97104if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments