Last active
July 25, 2022 20:15
-
-
Save kieranjol/d715b7425b90307440af12477ae29ec4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #usr/bin/env python | |
| import sys | |
| import ififuncs | |
| csv_file = sys.argv[1] | |
| csv_dict = ififuncs.extract_metadata(csv_file) | |
| habitat_dict = {} | |
| for entry in csv_dict[0]: | |
| if entry['share'] == 'preservation_storage': | |
| accession_number = entry['path'].split('/')[1] | |
| if accession_number[:2] == 'aa': | |
| raw_tape_list = (entry['stloc_state_method'].split('|')) | |
| if len(raw_tape_list) > 1: | |
| if accession_number in habitat_dict: | |
| tape_list = habitat_dict[accession_number] | |
| else: | |
| tape_list = [] | |
| tape1 = raw_tape_list[0].split(':')[0].strip() | |
| if accession_number in habitat_dict: | |
| if tape1 not in tape_list: | |
| tape_list.append(tape1) | |
| else: | |
| tape_list.append(tape1) | |
| tape2 = raw_tape_list[1].split(':')[0].strip() | |
| if accession_number in habitat_dict: | |
| if tape2 not in tape_list: | |
| tape_list.append(tape2) | |
| else: | |
| tape_list.append(tape2) | |
| tape3 = raw_tape_list[2].split(':')[0].strip() | |
| if accession_number in habitat_dict: | |
| if tape3 not in tape_list: | |
| tape_list.append(tape3) | |
| else: | |
| tape_list.append(tape3) | |
| habitat_dict[accession_number] = tape_list | |
| #habitat_dict[accession_number] = entry['stloc_state_method'] | |
| outliers = [] | |
| csv_headings = 'Accession Number, Habitat, backup_habitat' | |
| print(csv_headings) | |
| for key,value in sorted(habitat_dict.items()): | |
| string = '' | |
| #print key, " => " , value | |
| if len(value) == 3: | |
| primary_habitat = 'preservation_storage, %s, comms_room|' % value[0] | |
| for habitat in value[1:]: | |
| string += 'preservation_storage, %s, comms_room|' % habitat | |
| print('%s,%s,%s' % (key, primary_habitat, string)) | |
| else: | |
| outliers.append([key, value]) | |
| for i in outliers: | |
| print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment