diff --git a/src/pyamsd/commands/to_csv.py b/src/pyamsd/commands/to_csv.py index 7d569c7..c926596 100644 --- a/src/pyamsd/commands/to_csv.py +++ b/src/pyamsd/commands/to_csv.py @@ -34,6 +34,7 @@ def run(args): 'linked_filenames': {}, 'item_type': {}, 'item_subtype': {}, + 'state_territory': {}, 'cultural_region': {}, 'material': {}, 'technique': {}, @@ -91,6 +92,7 @@ def run(args): col_name = fields[j][2] if col_name in ['related_entries', 'irn']: a = map(str.strip, re.split(fields[j][3], col)) + a = [x for x in a if x.strip()] data.append(';'.join(a)) else: print('Check init of field {}\n').format(col_name) @@ -158,15 +160,16 @@ def run(args): # check related_entries for i, s in enumerate(csv_dataframe['sticks']): - if i > 0 and s[42].strip(): - rids = s[42].split(';') + if i > 0 and s[43].strip(): + rids = s[43].split(';') + # rids = [s.strip() for s in rids] for rid in rids: if rid not in unique_ids_check: - print('Related entry ID {} in line {} not found as AMSD ID\n'.format(rid, i+1)) + print('Related entry ID ::{}:: in line {} not found as AMSD ID\n'.format(rid, i+1)) if rid == s[1]: - print('Related entry ID {} in line {} refers to itself\n'.format(rid, i+1)) + print('Related entry ID ::{}:: in line {} refers to itself\n'.format(rid, i+1)) if rid in unclear_ids: - print('Related entry ID {} in line {} is marked as occurring more than once\n'.format(rid, i+1)) + print('Related entry ID ::{}:: in line {} is marked as occurring more than once\n'.format(rid, i+1)) if not args.dry_run: for filename, data in csv_dataframe.items(): diff --git a/src/pyamsd/commands/upload_media.py b/src/pyamsd/commands/upload_media.py index 893a9ca..891c606 100644 --- a/src/pyamsd/commands/upload_media.py +++ b/src/pyamsd/commands/upload_media.py @@ -15,6 +15,9 @@ def run(args): 'moviefile': ['mp4']} with args.api.get_catalog() as cat: + + name_uid_map = {obj.metadata['name']: obj for obj in cat} + for ifn in sorted(args.upload_path.iterdir()): print(ifn.name) @@ -28,6 +31,12 @@ def run(args): print('No supported media format - skipping {0}'.format(fmt)) continue + if str(ifn.stem) in name_uid_map: + cat_obj = name_uid_map[str(ifn.stem)] + cat_obj_id = name_uid_map[str(ifn.stem)].id + print('{}: object {} exists - will be deleted'.format(ifn.name, cat_obj_id)) + cat.delete(cat_obj_id) + md = { 'collection': 'amsd', 'name': str(ifn.stem), diff --git a/src/pyamsd/util.py b/src/pyamsd/util.py index a30da9b..3e2c8ec 100644 --- a/src/pyamsd/util.py +++ b/src/pyamsd/util.py @@ -15,6 +15,7 @@ [0, 'Place Created', 'place_created', ''], [1, 'Item type', 'item_type', ''], [1, 'Subtype', 'item_subtype', ''], + [0, 'State or territory', 'state_territory', ''], [1, 'Cultural region', 'cultural_region', ''], [1, 'Linguistic area', 'ling_area_1', r'Chirila\s*:\s*(.*?) +Austlang\s*:\s*(.*?)\s*:(.*?) +Glottolog\s*:\s*(.*)\s*'], @@ -49,7 +50,7 @@ [0, 'URL (source document)', 'url_source_1', ''], [0, 'URL (source document 2)', 'url_source_2', ''], [0, 'IRN', 'irn', r' *; *'], - [0, 'Related entries', 'related_entries', r' +'], + [0, 'Related entries', 'related_entries', r'[ ,;]+'], [0, 'Notes', 'notes', ''], [1, 'Data entry (OCCAMS)', 'data_entry', r' +'], [1, 'Linked Filename', 'linked_filenames', r' *; *']