This script will read in all objects in the objects folder, determine if they are different from the database object, and post or patch them to the database.
Authentication is determined from the keys.txt file.
'''
# FUTURE: Should also be deal with errors that are only dependency based.
# load objects in object folder. MODIFY TO HAVE USER VIEW AND SELECT OBJECTS
#object_filenames = os.listdir('objects/')
# run for each object in objects folder
#for object_filename in object_filenames:
#if '.json' in object_filename:
# load object SHOULD HANDLE ERRORS GRACEFULLY
print('Opening '+data_file)
object_list=ReadJSON(data_file)
# PUT OVERRIDE: SET THIS TO TRUE IF YOU WANT TO PUT INSTEAD OF PATCH
put_status=False
counter_post_success=0
counter_post_fail=0
counter_patch_success=0
counter_patch_fail=0
fornew_objectinobject_list:
# define object parameters. NEEDS TO RUN A CHECK TO CONFIRM THESE EXIST FIRST.
object_type=str(new_object[u'@type'][0])
# if the accession does not exist, make it blank
ifnew_object.has_key(u'accession'):
object_name=str(new_object[u'accession'])
else:
object_name=''
ifnew_object.has_key(u'uuid'):
object_uuid=str(new_object[u'uuid'])
else:
object_uuid=''
# if the id does not exist, assign the uuid. if no uuid, blank.