importargparsefromoffice365.sharepoint.client_contextimportClientContextfromtests.settingsimportclient_id,password,site_url,tenant,usernamedefmain():parser=argparse.ArgumentParser(description="Bulk-update list items via $batch")parser.add_argument("--list-title",default="Documents",help="list title")parser.add_argument("--title-prefix",default="Bulk item",help="only items with this title prefix are updated")parser.add_argument("--new-title-suffix",default=" (updated)",help="text appended to each title")parser.add_argument("--batch-size",type=int,default=100,help="operations per batch request")args=parser.parse_args()ctx=ClientContext(site_url).with_username_and_password(tenant=tenant,client_id=client_id,username=username,password=password)items=ctx.web.lists.get_by_title(args.list_title).items.get().execute_query()updated=0foriteminitems:title=item.properties.get("Title")or""iftitle.startswith(args.title_prefix):item.set_property("Title",f"{title}{args.new_title_suffix}").update()updated+=1ctx.execute_batch(args.batch_size)print(f"{updated} items queued for update")if__name__=="__main__":main()