importargparseimportosimporttempfilefromoffice365.sharepoint.client_contextimportClientContextfromoffice365.sharepoint.listitems.listitemimportListItemfromoffice365.sharepoint.lists.exporterimportExportListProgressfromtests.settingsimportcert_path,cert_thumbprint,client_id,site_url,tenantdefmain():parser=argparse.ArgumentParser(description="Export a list as a package (.zip)")parser.add_argument("--list-title",default="Orders",help="list title")parser.add_argument("--output",default=None,help="output zip path (default: temp)")args=parser.parse_args()ctx=ClientContext(site_url).with_client_certificate(tenant,client_id=client_id,thumbprint=cert_thumbprint,cert_path=cert_path)lst=ctx.web.lists.get_by_title(args.list_title)export_path=args.outputoros.path.join(tempfile.mkdtemp(),f"{args.list_title}.zip")defprint_progress(progress:ExportListProgress)->None:kind="item"ifisinstance(progress.current_item,ListItem)else"file"print(f"Exported {kind}: {progress.processed_items}/{progress.total_items}")withopen(export_path,"wb")asf:lst.export(f,True,print_progress).execute_query()print(f"Exported '{args.list_title}' to {export_path}")if__name__=="__main__":main()