Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. #!/usr/bin/env python
  2. '''
  3.  
  4. '''
  5. import os
  6. import sys
  7. import argparse
  8. import csv
  9. import ififuncs
  10.  
  11. def parse_args(args_):
  12. '''
  13. Parse command line arguments.
  14. '''
  15. parser = argparse.ArgumentParser(
  16. description='Analyses the CSV file reports from Strongbox.'
  17. 'Prints the output to the terminal if the -manifest option is not used'
  18. 'if the -manifest option is used, just the differences, if any, will appear on screen'
  19. ' Written by Kieran O\'Leary.'
  20. )
  21. parser.add_argument(
  22. '-register', help='Path to helper accessions register'
  23. )
  24. parser.add_argument(
  25. '-technical',
  26. help='Path to technical/PBCore CSV.'
  27. )
  28. parser.add_argument(
  29. '-filmographic',
  30. help='Path to Filmographic CSV. Must contain reference numbers.'
  31. )
  32. parsed_args = parser.parse_args(args_)
  33. return parsed_args
  34.  
  35.  
  36. def find_checksums(csv_file, identifier):
  37. '''
  38. Finds the relevant entries in the CSV and prints to terminal
  39. '''
  40. csv_dict = ififuncs.extract_metadata(csv_file)
  41. manifest_lines = []
  42. for items in csv_dict:
  43. for x in items:
  44. if type(x) is dict:
  45. if identifier in x['path']:
  46. identifier_string = "/%s/" % identifier
  47. manifest_line = x['hash_code'] + ' ' + x['path'].replace(identifier_string, '')
  48. manifest_lines.append(manifest_line)
  49. strongbox_list = sorted(manifest_lines, key=lambda x: (x[130:]))
  50. return strongbox_list
  51.  
  52. def main(args_):
  53. args = parse_args(args_)
  54. register_dict = ififuncs.extract_metadata(args.register)[0]
  55. technical_dict = ififuncs.extract_metadata(args.technical)[0]
  56. filmographic_dict = ififuncs.extract_metadata(args.filmographic)[0]
  57. for accession in register_dict:
  58. number = accession['accession number']
  59. for technical_record in technical_dict:
  60. if technical_record['Accession Number'] == number:
  61. accession['acquisition method'] = technical_record['Type Of Deposit']
  62. accession['acquired from'] = technical_record['Donor']
  63. accession['date acquired'] = technical_record['Date Of Donation']
  64. for filmographic_record in filmographic_dict:
  65. if filmographic_record['Reference Number'] == technical_record['Reference Number']:
  66. simple = '%s (%s) | %s' % (filmographic_record['Title'], filmographic_record['Year'], technical_record['dig_object_descrip'])
  67. if accession['acquisition method'] == 'Reproduction':
  68. simple += ' | Reproduction of %s' % technical_record['TTape Origin']
  69. accession['simple name; basic description; identification; historical information'] = simple
  70.  
  71. print technical_record['Reference Number']
  72. print
  73. print technical_record['Date Of Donation']
  74. print accession
  75. with open('accesssss.csv', 'w') as csvfile:
  76. fieldnames = ififuncs.extract_metadata(args.register)[1]
  77. writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
  78. writer.writeheader()
  79. for i in register_dict:
  80. writer.writerow(i)
  81.  
  82.  
  83.  
  84. if __name__ == '__main__':
  85. main(sys.argv[1:])
Add Comment
Please, Sign In to add comment