Skip to content

Commit

Permalink
added state_territory; minor fix to related_entries; delete obj if ex…
Browse files Browse the repository at this point in the history
…isting during upload
  • Loading branch information
Bibiko committed Feb 6, 2024
1 parent b383c1b commit b789ffe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/pyamsd/commands/to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run(args):
'linked_filenames': {},
'item_type': {},
'item_subtype': {},
'state_territory': {},
'cultural_region': {},
'material': {},
'technique': {},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
9 changes: 9 additions & 0 deletions src/pyamsd/commands/upload_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/pyamsd/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*'],
Expand Down Expand Up @@ -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' *; *']
Expand Down

0 comments on commit b789ffe

Please sign in to comment.