efilenames = {} for efile in efiles: efilenames[efile['attachment_links'][0]['name']] = efile['id'] print efilenames enames = {} for eper in epers: enames[eper['code']] = eper print enames pers = glob('pers/*.json') for per in pers: with open(per) as json_data: temp = json.load(json_data) json_data.close() data = { 'code': temp['name'], 'description': temp['desc'], 'sg_arcana': temp['arcana'], 'sg_level': (int)(temp['level']), 'sg_json': None } if temp['name'] not in enames: data['project'] = {'type': 'Project', 'id': 70} id = sg.create('CustomEntity07', data, ['id'])['id'] else: id = sg.update('CustomEntity07', enames[temp['name']]['id'], data)['id'] if temp['name'] in efilenames: sg.delete('Attachment', efilenames[temp['name']]) sg.upload('CustomEntity07', id, per, 'sg_json')
''' Call this script from the command line as python delete_actionmenu.py ***you MUST know the ID of the action menu you want to delete and enter it below This is a very stupid script and is provided as a utility only Documentation to come - note that you will have to write a find routine to find the correct ID to delete! Author Tom Stratton / tom at tomstratton dot net ''' from shotgun_api3 import Shotgun from pprint import pprint SERVER_PATH = 'https://*****.shotgunstudio.com' #your server path here SCRIPT_USER = '******' #your script name SCRIPT_KEY = '********' #your key here sg = Shotgun(SERVER_PATH, SCRIPT_USER, SCRIPT_KEY) ID_TO_DELELE = 1 sg.delete('ActionMenuItem', ID_TO_DELELE) # note that the id numbers will have to be either found or remembered!
config = blob['config'] payload = blob['data'] sg = Shotgun(config['shotgun_url'], config['script_name'], config['script_api_key'], 'api3_preview') if method == 'find': result = sg.find(payload['entity'], payload['filters'], payload['fields'], payload['order'], payload['filter_operator'], payload['limit'], payload['retired_only']) elif method == 'find_one': result = sg.find_one(payload['entity'], payload['filters'], payload['fields'], payload['order'], payload['filter_operator']) elif method == 'create': result = sg.create(payload['entity'], payload['data']) elif method == 'update': result = sg.update(payload['entity'], payload['id'], payload['data']) elif method == 'delete': result = sg.delete(payload['entity'], payload['id']) elif method == 'upload': result = sg.upload(payload['entity'], payload['id'], payload['path'], payload['field_name'], payload['display_name']) elif method == 'upload_thumbnail': result = sg.upload_thumbnail(payload['entity'], payload['id'], payload['path']) elif method == 'schema_field_read': result = sg.schema_field_read(payload['entity']) elif method == 'schema_field_create': result = sg.schema_field_create(payload['entity'], payload['type'], payload['name'], payload['attrs']) elif method == '_url_for_attachment_id': entity_id = payload['id'] # Do a lot of legwork (based on Shotgun.download_attachment()) sid = sg._get_session_token() domain = urlparse(sg.base_url)[1].split(':',1)[0] cj = cookielib.LWPCookieJar()