Created
June 18, 2018 13:08
-
-
Save kieranjol/e04914ca87d00c31e585096664962ed2 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
| import ififuncs | |
| import sys | |
| import csv | |
| # Create a list containing dictionaries of the spreadsheet values, and the relevant headings. | |
| filmo_data = ififuncs.extract_metadata(sys.argv[1]) | |
| tech_data = ififuncs.extract_metadata(sys.argv[2]) | |
| # This just isolates the list of dictionaries, not the spreadsheet headings. | |
| filmo_dict = filmo_data[0] | |
| tech_dict = tech_data[0] | |
| # Initialising some empty lists that we will populate by auditing the data later in the script. | |
| new_tech_list = [] | |
| filmo_records_with_tech_records = [] | |
| # Loop through each filmographic record | |
| for filmo_record in filmo_dict: | |
| #print filmo_record | |
| # Grab the OE number for a record | |
| filmo_oe_number = filmo_record['Object Entry'] | |
| # For each OE number in the filmographic, loop through the tech records.. | |
| for tech_record in tech_dict: | |
| # Keep looping through the tech records until the Object Entry number matches the one in the filmographic | |
| tech_oe_number = tech_record['Reference Number'] | |
| if filmo_oe_number == tech_oe_number: | |
| # updates the 'new tech record' with the correct AFXXXXX reference number. | |
| tech_record['new_ref'] = filmo_record['Reference Number'] | |
| new_tech_list.append(tech_record) | |
| #print tech_record['Accession Number'], filmo_oe_number, tech_oe_number, filmo_record['Reference Number'], tech_record['new_ref'] | |
| filmo_records_with_tech_records.append(filmo_record['Reference Number']) | |
| all_filmos = [] | |
| for i in filmo_dict: | |
| all_filmos.append(i['Reference Number']) | |
| for x in all_filmos: | |
| if x not in filmo_records_with_tech_records: | |
| print x | |
| with open(sys.argv[3], 'w') as csvfile: | |
| fieldnames = tech_data[1] | |
| writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter=',', lineterminator='\n') | |
| writer.writeheader() | |
| for i in new_tech_list: | |
| writer.writerow(i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment