diff --git a/FoxmlWorker.py b/FoxmlWorker.py index e31ece3..b990cd0 100644 --- a/FoxmlWorker.py +++ b/FoxmlWorker.py @@ -140,4 +140,5 @@ class FWorker: if __name__ == '__main__': FW = FWorker('assets/sample_fox.xml') + print(FW.get_datastream_types()) diff --git a/ImportServerUtilities.py b/ImportServerUtilities.py index fd1c318..a9c24c9 100644 --- a/ImportServerUtilities.py +++ b/ImportServerUtilities.py @@ -5,9 +5,10 @@ import csv import shutil from pathlib import Path from urllib.parse import unquote - +from typing import Optional, List import FoxmlWorker as FW import ImportUtilities as IU +import json class ImportServerUtilities: @@ -80,7 +81,7 @@ class ImportServerUtilities: # Copies digital assets from dataStream store to staging directory @IU.ImportUtilities.timeit - def stage_files(self, content_model, datastreams=None): + def stage_files(self, content_model: str, datastreams: Optional[List] = None) -> None: if datastreams is None: datastreams = ['OBJ'] pids = self.iu.get_pids_by_content_model(self.namespace, content_model) @@ -159,9 +160,30 @@ class ImportServerUtilities: cursor.execute(command) self.iu.conn.commit() + def get_dsids_with_count(self, namespace): + dsids = {} + pids = self.get_pids_from_objectstore('ivoices') + for pid in pids: + foxml_file = self.iu.dereference(pid) + foxml = f"{self.objectStore}/{foxml_file}" + if (foxml): + fw = FW.FWorker(foxml) + if fw.get_state() != 'Active': + continue + datastreams = fw.get_datastream_types() + for datastream, in datastreams.keys(): + count = dsids.get(datastream) + if count is not None: + dsids[datastream] = count + 1 + else: + datastreams[datastream] = 1 + with open("dsid.json", "w") as file: + json.dump(dsids, file, indent=4) + + if __name__ == '__main__': MS = ImportServerUtilities('ivoices') - MS.stage_files('') + MS.get_dsids_with_count('ivoices') diff --git a/ImportUtilities.py b/ImportUtilities.py index 0d06a15..569af05 100644 --- a/ImportUtilities.py +++ b/ImportUtilities.py @@ -337,7 +337,21 @@ class ImportUtilities: return relationships + import csv + + def make_media_add_worksheet(self, input_file, output_file): + with open(output_file, mode="w", newline="") as out_file: # Avoid shadowing `output_file` + writer = csv.DictWriter(out_file, fieldnames=['node_id', 'file']) + writer.writeheader() + with open(input_file, "r") as file: + for line in file: # Iterate directly over lines + row = { + 'node_id': line.split('_')[0], # Get everything before the first underscore + 'file': line.strip() # Remove trailing newlines + } + writer.writerow(row) + if __name__ == '__main__': MU = ImportUtilities('ivoices') - print(MU.get_pids_by_content_model('ivoices', 'audioCModel')) \ No newline at end of file + MU.make_media_add_worksheet('inputs/ivoice_file.txt', 'outputs/ivoice_media.csv') \ No newline at end of file