{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport pandas_profiling as pp\nfrom google.cloud import storage\nPROJECT = 'data-science-project-374708'\nbucket_name = 'rsna-breast-cancer-detection-talluri'\nstorage_client = storage.Client(project=PROJECT)\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-01-15T05:01:33.659616Z","iopub.execute_input":"2023-01-15T05:01:33.660047Z","iopub.status.idle":"2023-01-15T05:01:33.666975Z","shell.execute_reply.started":"2023-01-15T05:01:33.660011Z","shell.execute_reply":"2023-01-15T05:01:33.665526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n# copy and paste all the helper function defined above.\ndef create_bucket(bucket_name):\n    bucket = storage_client.bucket(bucket_name)\n    bucket.create(location='US')\n    print(f'Bucket {bucket.name} created.')\n\ndef upload_blob(bucket_name, source_file_name, destination_blob_name):\n    \"\"\"Uploads a file to the bucket. https://cloud.google.com/storage/docs/ \"\"\"\n    bucket = storage_client.get_bucket(bucket_name)\n    blob = bucket.blob(destination_blob_name)\n    blob.upload_from_filename(source_file_name)\n    print('File {} uploaded to {}.'.format(\n        source_file_name,\n        destination_blob_name))\n    \ndef list_blobs(bucket_name):\n    \"\"\"Lists all the blobs in the bucket. https://cloud.google.com/storage/docs/\"\"\"\n    blobs = storage_client.list_blobs(bucket_name)\n    for blob in blobs:\n        print(blob.name)\n        \ndef download_to_kaggle(bucket_name, destination_directory, file_name):\n    \"\"\"Takes the data from your GCS Bucket and puts it into the working directory of your Kaggle notebook\"\"\"\n    os.makedirs(destination_directory, exist_ok = True)\n    full_file_path = os.path.join(destination_directory, file_name)\n    blobs = storage_client.list_blobs(bucket_name)\n    for blob in blobs:\n        blob.download_to_filename(full_file_path)\n    \n    \ndef upload_files(bucket_name, source_folder):\n    bucket = storage_client.get_bucket(bucket_name)\n    for filename in os.listdir(source_folder):\n        blob = bucket.blob(filename)\n        blob.upload_from_filename(source_folder + filename)\n\n        \n        \nprint(\"I am running\")\n        \ntry:\n    print(\"Creating bucket {}\".format(bucket_name))\n    create_bucket(bucket_name)   \nexcept Exception as e:\n    print(e)\n    pass\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\ncount = 0\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    if count == 5:\n        break\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n    count = count + 1\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"execution":{"iopub.status.busy":"2023-01-15T05:05:46.444944Z","iopub.execute_input":"2023-01-15T05:05:46.44534Z","iopub.status.idle":"2023-01-15T05:05:50.288116Z","shell.execute_reply.started":"2023-01-15T05:05:46.445309Z","shell.execute_reply":"2023-01-15T05:05:50.287249Z"},"trusted":true},"execution_count":null,"outputs":[]}]}