def update_video(cms_api: CMS, vid_id: str, update_data: Union[str, dict]) -> None: """ Updates a video using the data in the JSON. Args: cms_api (CMS): CMS API instance to use. video_id (str): Video ID to update. update_data (Union[str, dict]): Update data in JSON format. """ vid_id = normalize_id(vid_id) if vid_id: response = cms_api.UpdateVideo(video_id=vid_id, json_body=update_data).status_code print(f'Updating video ID "{vid_id}": {response}') if response == 429: for remaining in range(3, 0, -1): sys.stderr.write(f'\rRetrying in {remaining:2d} seconds.') sys.stderr.flush() time.sleep(1) # let's call ourself again, shall we? update_video(cms_api=cms_api, vid_id=vid_id, update_data=update_data)
client_secret = '' # get account info from config file if not hardcoded if None in [account_id, client_id, client_secret]: try: account_id, client_id, client_secret, _ = load_account_info( args.config) except Exception as e: print(e) sys.exit(2) # if account ID was provided override the one from config account_id = args.account or account_id # create a CMS API instance cms = CMS(oauth=OAuth( account_id=account_id, client_id=client_id, client_secret=client_secret)) row_list = [[ 'id', 'account_id', 'name', 'created_at', 'updated_at', 'video_count' ]] response = cms.GetFolders() if response.status_code == 200: folders = response.json() for folder in folders: row = [folder.get(field) for field in row_list[0]] row_list.append(row) #write list to file try:
# get account info from config file if not hardcoded if '' in [account_id, client_id, client_secret]: try: account_id, client_id, client_secret, opts = load_account_info( args.config) except Exception as e: print(e) sys.exit(2) # if account ID was provided override the one from config account_id = args.account or account_id # create a CMS API instance cms = CMS( OAuth(account_id=account_id, client_id=client_id, client_secret=client_secret)) # list to contain all video IDs video_list = [] # if we have an xls/csv if args.xls: try: video_list = videos_from_file( args.xls, column_name=args.column if args.column else 'video_id') except Exception as e: print(e) # otherwise just use the options from the config file elif opts:
# parse the args args = parser.parse_args() # get account info from config file try: account_id, client_id, client_secret, _ = load_account_info(args.config) except Exception as e: print(e) sys.exit(2) # if account ID was provided override the one from config account_id = args.account or account_id # create a CMS API instance cms = CMS( OAuth(account_id=account_id, client_id=client_id, client_secret=client_secret)) # delete one or all subscriptions if args.delete: if args.delete == 'all': sub_list = cms.GetSubscriptionsList().json() for sub in sub_list: print(cms.DeleteSubscription(sub_id=sub['id']).text) else: print(cms.DeleteSubscription(sub_id=args.delete).text) # add a subscription if args.add: print(cms.CreateSubscription(callback_url=args.add).text)
args = parser.parse_args() if not all([args.f, args.t]): print('Need from and to account IDs') sys.exit(2) # get account info from config file if not hardcoded try: account_id, client_id, client_secret, _ = load_account_info(args.i) except (OSError, JSONDecodeError) as e: print(e) sys.exit(2) # if account ID was provided override the one from config account_id = args.f or account_id # create a CMS API instance cms = CMS(oauth=OAuth(account_id=account_id,client_id=client_id, client_secret=client_secret)) # make API call response = cms.GetCustomFields() # copy all fields from one account to the other if response.status_code == 200: custom_fields : dict = response.json() for field in custom_fields: r = cms.CreateCustomField(account_id=args.t, json_body=field) print(field.get('id'), r.status_code, sep=', ') else: eprint(f'Error while trying to get custom fields: {response.status_code}')
parser.add_argument('-l', action='store_true', default=False, help='List all custom fields') # parse the args args = parser.parse_args() # get account info from config file if not hardcoded try: account_id, client_id, client_secret, _ = load_account_info(args.i) except (OSError, JSONDecodeError) as e: print(e) sys.exit(2) # if account ID was provided override the one from config account_id = args.t or account_id # create a CMS API instance cms = CMS(oauth=OAuth(account_id=account_id,client_id=client_id, client_secret=client_secret)) # make API call response = cms.GetCustomFields() # list all fields that don't match known Beacon field patterns if response.status_code == 200: custom_fields : dict = response.json() for field in custom_fields: current_field = field.get('id', '') if sanitize(current_field) not in good_fields or args.l: print(current_field) else: eprint(f'Error while trying to get custom fields: {response.status_code}')