fix_ia_subject.py 960 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. '''Script to add subject tags with the shortener project ids.'''
  2. import internetarchive
  3. ACCESS_KEY = 'TODO'
  4. SECRET_KEY = 'TODO'
  5. def main():
  6. search = internetarchive.search.Search('urlteam terroroftinytown -collection:test_collection')
  7. for result in search:
  8. print(result)
  9. item = internetarchive.get_item(result['identifier'])
  10. if not item.metadata['subject'] == 'urlteam;terroroftinytown':
  11. continue
  12. subjects = ['urlteam', 'terroroftinytown', 'archiveteam']
  13. for file_obj in item.iter_files():
  14. if file_obj.name.endswith('.zip'):
  15. shortener_id = file_obj.name.split('.', 1)[0]
  16. subjects.append(shortener_id)
  17. new_subject = ';'.join(subjects)
  18. print(new_subject)
  19. item.modify_metadata(
  20. {'subject': new_subject},
  21. access_key=ACCESS_KEY, secret_key=SECRET_KEY
  22. )
  23. if __name__ == '__main__':
  24. main()