{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":71549,"databundleVersionId":8561470,"sourceType":"competition"}],"dockerImageVersionId":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from boto3.session import Session\nimport boto3\nimport os\nfrom tqdm import tqdm\nimport glob\n\n# s3-subfolder-user\n\nBUCKET_NAME = 'kaggle-rsna24'\nACCESS_KEY = 'AKIAZHGZ27KUTXYUYGVQ'\nSECRET_KEY = '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'\n\nsession = Session(aws_access_key_id=ACCESS_KEY,\n              aws_secret_access_key=SECRET_KEY)\ns3 = session.resource('s3')\nyour_bucket = s3.Bucket(BUCKET_NAME)","metadata":{"execution":{"iopub.status.busy":"2024-09-04T13:24:05.611799Z","iopub.execute_input":"2024-09-04T13:24:05.61275Z","iopub.status.idle":"2024-09-04T13:24:06.860845Z","shell.execute_reply.started":"2024-09-04T13:24:05.612703Z","shell.execute_reply":"2024-09-04T13:24:06.859328Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fns = []\nfor s3_file in your_bucket.objects.all():\n    fns += [s3_file.key]","metadata":{"execution":{"iopub.status.busy":"2024-09-04T13:24:06.863196Z","iopub.execute_input":"2024-09-04T13:24:06.863727Z","iopub.status.idle":"2024-09-04T13:24:10.68071Z","shell.execute_reply.started":"2024-09-04T13:24:06.863691Z","shell.execute_reply":"2024-09-04T13:24:10.679408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fns  = [fn for fn in fns if 'models/cfg_dh_14s10a_locsag' in fn ]\nfns","metadata":{"execution":{"iopub.status.busy":"2024-09-04T13:24:10.682111Z","iopub.execute_input":"2024-09-04T13:24:10.68246Z","iopub.status.idle":"2024-09-04T13:24:10.693433Z","shell.execute_reply.started":"2024-09-04T13:24:10.682429Z","shell.execute_reply":"2024-09-04T13:24:10.692203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for fn in tqdm(fns):\n    target_folder = '/'.join(fn.split('/')[:-1]).replace('models/cfg_dh_14s10a_locsag/','')\n    target_file = fn.split('/')[-1]\n    os.makedirs(target_folder, exist_ok=True)\n    print(fn, ' -> ', target_folder + '/' + target_file)\n    s3.Bucket(BUCKET_NAME).download_file(fn, target_folder + '/' + target_file)","metadata":{"execution":{"iopub.status.busy":"2024-09-04T13:24:10.695745Z","iopub.execute_input":"2024-09-04T13:24:10.696304Z","iopub.status.idle":"2024-09-04T13:24:16.556037Z","shell.execute_reply.started":"2024-09-04T13:24:10.696259Z","shell.execute_reply":"2024-09-04T13:24:16.554866Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}