From 27cca312c197a8aaf6ae6d37378b5f60efb391f1 Mon Sep 17 00:00:00 2001 From: maxisoft Date: Sat, 27 Jul 2024 13:46:30 +0200 Subject: [PATCH 1/4] Update workflow configurations ([DOIT, PULL]) **Changes:** * **Python version change:** Both `.github/workflows/doit.yml` and `.github/workflows/pull.yml` now leverage Python 3.11 * **Improved caching for pip dependencies:** The `cache` step is now conditional on the Python version. This ensures caching only occurs for non-GraalPython environments, optimizing workflow execution time and reducing unnecessary storage usage. --- .github/workflows/doit.yml | 3 ++- .github/workflows/pull.yml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doit.yml b/.github/workflows/doit.yml index c3d062a..e4a76c3 100644 --- a/.github/workflows/doit.yml +++ b/.github/workflows/doit.yml @@ -7,7 +7,7 @@ on: - cron: "33 18 * * *" env: - PYTHON_VERSION: "graalpy-24" + PYTHON_VERSION: "3.11" permissions: contents: read @@ -29,6 +29,7 @@ jobs: python-version: "${{ env.PYTHON_VERSION }}" - name: Cache pip dependencies + if: !startsWith('graal', env.PYTHON_VERSION) && ${{ github.actor == github.repository_owner }} uses: actions/cache@v4 with: path: ~/.cache/pip diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index f94a752..37a2379 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -4,7 +4,7 @@ on: pull_request: env: - PYTHON_VERSION: "graalpy-24" + PYTHON_VERSION: "3.11" permissions: contents: read @@ -26,7 +26,7 @@ jobs: python-version: "${{ env.PYTHON_VERSION }}" - name: Cache pip dependencies - if: ${{ github.actor == github.repository_owner }} + if: !startsWith('graal', env.PYTHON_VERSION) && ${{ github.actor == github.repository_owner }} uses: actions/cache@v4 with: path: ~/.cache/pip From 91f36400bb1a6d2a2c114caf23918d6e22730f01 Mon Sep 17 00:00:00 2001 From: maxisoft Date: Sat, 27 Jul 2024 14:17:24 +0200 Subject: [PATCH 2/4] Add manual trigger to GitHub Actions workflows - Added `workflow_dispatch` event to `.github/workflows/doit.yml` and `.github/workflows/pull.yml` to enable manual triggering of workflows from the GitHub Actions page. --- .github/workflows/doit.yml | 1 + .github/workflows/pull.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/doit.yml b/.github/workflows/doit.yml index e4a76c3..9ac142d 100644 --- a/.github/workflows/doit.yml +++ b/.github/workflows/doit.yml @@ -5,6 +5,7 @@ on: branches: [ "main" ] schedule: - cron: "33 18 * * *" + workflow_dispatch: env: PYTHON_VERSION: "3.11" diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 37a2379..e7907b4 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -2,6 +2,7 @@ name: pull request lint and test on: pull_request: + workflow_dispatch: env: PYTHON_VERSION: "3.11" From 2a6e77552f26aad9665f3a77f917d4d0433ff47f Mon Sep 17 00:00:00 2001 From: maxisoft Date: Sat, 27 Jul 2024 14:26:18 +0200 Subject: [PATCH 3/4] Added a Readme.md --- Readme.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..834c6f5 --- /dev/null +++ b/Readme.md @@ -0,0 +1,69 @@ +## Kaggle Notebook Backup 📚 + +This Python script automates downloading your Kaggle notebooks, including private ones (if desired), and creates a compressed archive for easy backup or transfer. + +### **Local Installation:** + +1. **Prerequisites:** + - Python 3.x + - `kaggle` and other packages: Install with `pip install -r requirements.txt` + - Set up the Kaggle CLI according to the [official documentation](https://www.kaggle.com/docs/api) +2. **Download the repo:** + + ```bash + git clone https://github.com/maxisoft/kaggle-notebook-backup.git + ``` + +3. **Run the script:** + + ```bash + python main.py [OPTIONS] + ``` + +#### Options: + +* `-o, --output` (default: `./kernels.zip`): Name and location of the output archive. +* `-p, --include-private` (default: `True`): Include private notebooks in the backup. +* `-u, --user` (default: `current user`): Kaggle username whose notebooks to download. +* `-t, --tmp-dir` (default: `temporary directory`): Path to a custom temporary directory. + +#### Default Behavior: + +The default execution will create an archive named `kernels.zip` with all your Kaggle kernels in the *current directory*. + +### Running via GitHub Actions Workflow 🚀 + +This repository also includes a GitHub Actions workflow named `doit.yml` that can be used to automate the script execution on a schedule or upon pushes to the `main` branch. +To enable this functionality, you'll need to configure secrets within your repository settings. + +**Here's a breakdown of the steps involved:** + +1. **Fork this Repository:** Create your own fork of this repository on GitHub. +2. **Navigate to Actions:** Go to your forked repository's settings and then to the "Actions" tab. +3. **Enable the `doit.yml` Workflow:** Find the `doit.yml` workflow and enable it to run on pushes or schedules. +4. **Set Up Secrets (Required):** + + - Navigate to your repository's settings and then to "Secrets." + - Create two secrets: + - `KAGGLE_USERNAME`: Your Kaggle username. + - `KAGGLE_KEY`: Your Kaggle API key (obtainable from your profile settings). +5. **Manual Trigger:** +You can manually trigger the workflow by navigating to the “Actions” tab in your repository, selecting the `doit.yml` workflow, and clicking the “Run workflow” button. +6. **Output as GitHub Artifact:** + - The resulting zip file (`kernels.zip`) will be uploaded as a GitHub artifact, making it easy to download and access from the Actions tab. + +**Important Note:** + +- **Security:** Never store your API key directly in the code. Using GitHub secrets ensures secure handling of sensitive information. + +**Benefits of Using GitHub Actions:** + +- **Automated Execution:** The script runs automatically based on your chosen schedule, upon code pushes, or manually. +- **Regular Backups:** Scheduled execution helps maintain updated backups of your notebooks. +- **Reduced Manual Work:** Frees you from manually running the script, saving time and effort. + +By following these steps and leveraging GitHub Actions, you can automate the process of backing up your Kaggle notebooks, ensuring a more streamlined and safe workflow. + +### Contributing: + +Feel free to contribute bug fixes, improvements, or feature requests. Fork the repository, create a pull request, and share your changes! 🚀 From 44f814820c2bdca483dea5f1bfb2c69583c847a2 Mon Sep 17 00:00:00 2001 From: maxisoft Date: Sat, 27 Jul 2024 14:30:47 +0200 Subject: [PATCH 4/4] bugfix if syntax --- .github/workflows/doit.yml | 2 +- .github/workflows/pull.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doit.yml b/.github/workflows/doit.yml index 9ac142d..05949e0 100644 --- a/.github/workflows/doit.yml +++ b/.github/workflows/doit.yml @@ -30,7 +30,7 @@ jobs: python-version: "${{ env.PYTHON_VERSION }}" - name: Cache pip dependencies - if: !startsWith('graal', env.PYTHON_VERSION) && ${{ github.actor == github.repository_owner }} + if: ${{ !startsWith('graal', env.PYTHON_VERSION) && github.actor == github.repository_owner }} uses: actions/cache@v4 with: path: ~/.cache/pip diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index e7907b4..f250faf 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -27,7 +27,7 @@ jobs: python-version: "${{ env.PYTHON_VERSION }}" - name: Cache pip dependencies - if: !startsWith('graal', env.PYTHON_VERSION) && ${{ github.actor == github.repository_owner }} + if: ${{ !startsWith('graal', env.PYTHON_VERSION) && github.actor == github.repository_owner }} uses: actions/cache@v4 with: path: ~/.cache/pip