Skip to content

Commit 43bc62c

Browse files
committed
unused import removed.
1 parent 702dce1 commit 43bc62c

File tree

1 file changed

+96
-48
lines changed

1 file changed

+96
-48
lines changed
Lines changed: 96 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,125 @@
11
{
2-
"metadata": {
3-
"kernelspec": {
4-
"display_name": "python3",
5-
"name": "notebook"
6-
},
7-
"language_info": {
8-
"file_extension": ".py",
9-
"mimetype": "text/x-python",
10-
"name": "python"
11-
},
12-
"Last_Active_Cell_Index": 2
13-
},
14-
"nbformat_minor": 5,
15-
"nbformat": 4,
162
"cells": [
173
{
18-
"id": "80e69eae-cd44-4046-9f24-4cde652dbc0f",
194
"cell_type": "markdown",
20-
"source": "Oracle AI Data Platform v1.0\n\nCopyright © 2025, Oracle and/or its affiliates.\n\nLicensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/",
5+
"id": "80e69eae-cd44-4046-9f24-4cde652dbc0f",
216
"metadata": {
227
"type": "markdown"
23-
}
8+
},
9+
"source": [
10+
"Oracle AI Data Platform v1.0\n",
11+
"\n",
12+
"Copyright © 2025, Oracle and/or its affiliates.\n",
13+
"\n",
14+
"Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/"
15+
]
2416
},
2517
{
26-
"id": "f2356308-64bd-4fcb-ae88-5869a227eb2a",
2718
"cell_type": "markdown",
28-
"source": "### Sample Code: Downloading Notebooks/Files from Git.\n\nThis example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n\n\n**Note:** \n\n- Replace all placeholders (e.g., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>` etc.) with values specific to your environment before running the notebook. \n- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n- This notebook should be executed from AIDP.",
19+
"id": "f2356308-64bd-4fcb-ae88-5869a227eb2a",
2920
"metadata": {
3021
"type": "markdown"
31-
}
22+
},
23+
"source": [
24+
"### Sample Code: Downloading Notebooks/Files from Git.\n",
25+
"\n",
26+
"This example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n",
27+
"\n",
28+
"\n",
29+
"**Note:** \n",
30+
"\n",
31+
"- Replace all placeholders (e.g., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>` etc.) with values specific to your environment before running the notebook. \n",
32+
"- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n",
33+
"- This notebook should be executed from AIDP."
34+
]
3235
},
3336
{
34-
"id": "065a7b5a-727d-4297-a502-e92c074f626f",
3537
"cell_type": "code",
36-
"source": "# Username of Github\ngit_username = \"<GIT_USERNAME>\"\n# Access Token of Github\ngit_pat = \"<GIT_PAT>\"\n# AIDP Workspace path to download repository\naidp_path = \"<AIDP_WORKSPACE_PATH>\"\n# Github Repository Name\ngit_repo_name = \"<GIT_REPO_NAME>\"\n# Github Branch Name\ngit_branch = \"<GIT_BRANCH>\"",
38+
"execution_count": null,
39+
"id": "065a7b5a-727d-4297-a502-e92c074f626f",
3740
"metadata": {
3841
"execution": {
3942
"iopub.status.busy": "2025-11-04T14:37:15.709Z"
4043
},
41-
"type": "python",
42-
"trusted": true
44+
"trusted": true,
45+
"type": "python"
4346
},
4447
"outputs": [],
45-
"execution_count": 1
48+
"source": [
49+
"# Username of Github\n",
50+
"git_username = \"<GIT_USERNAME>\"\n",
51+
"# Access Token of Github\n",
52+
"git_pat = \"<GIT_PAT>\"\n",
53+
"# AIDP Workspace path to download repository\n",
54+
"aidp_path = \"<AIDP_WORKSPACE_PATH>\"\n",
55+
"# Github Repository Name\n",
56+
"git_repo_name = \"<GIT_REPO_NAME>\"\n",
57+
"# Github Branch Name\n",
58+
"git_branch = \"<GIT_BRANCH>\""
59+
]
4660
},
4761
{
48-
"id": "d730a44f-6582-40eb-8c72-f88519b01e23",
4962
"cell_type": "code",
50-
"source": "import requests\nimport zipfile\nimport io\nimport os\n\nif not git_pat:\n raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n\nzip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n\ntry:\n # Headers for PAT authentication\n headers = {\n \"Authorization\": f\"token {git_pat}\",\n \"Accept\": \"application/vnd.github.v3+json\"\n }\n\n print(f\"Downloading ZIP from {zip_url}...\")\n response = requests.get(zip_url, headers=headers, stream=True)\n response.raise_for_status()\n\n # Extract the ZIP content\n with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:\n \n top_level_folder = os.path.commonprefix(zip_ref.namelist())\n # Extract all files\n zip_ref.extractall(aidp_path)\n print(\"Repository downloaded and extracted successfully.\")\n\nexcept requests.exceptions.RequestException as e:\n print(f\"Error downloading repository: {e}\")\nexcept zipfile.BadZipFile:\n print(\"Downloaded file is not a valid ZIP file.\")\nexcept Exception as e:\n print(f\"An unexpected error occurred: {e}\")\n",
63+
"execution_count": null,
64+
"id": "d730a44f-6582-40eb-8c72-f88519b01e23",
5165
"metadata": {
5266
"execution": {
5367
"iopub.status.busy": "2025-11-04T14:37:29.146Z"
5468
},
55-
"type": "python",
56-
"trusted": true
69+
"trusted": true,
70+
"type": "python"
5771
},
58-
"outputs": [
59-
{
60-
"data": {
61-
"text/plain": "Downloading ZIP from https://api.github.com/repos/nishgit/git-sdk-test/zipball/main...\n"
62-
},
63-
"metadata": {},
64-
"output_type": "display_data"
65-
},
66-
{
67-
"data": {
68-
"text/plain": "Repository downloaded and extracted successfully.\n"
69-
},
70-
"metadata": {},
71-
"output_type": "display_data"
72-
}
73-
],
74-
"execution_count": 1
72+
"outputs": [],
73+
"source": [
74+
"import requests\n",
75+
"import zipfile\n",
76+
"import io\n",
77+
"\n",
78+
"if not git_pat:\n",
79+
" raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n",
80+
"\n",
81+
"zip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n",
82+
"\n",
83+
"try:\n",
84+
" # Headers for PAT authentication\n",
85+
" headers = {\n",
86+
" \"Authorization\": f\"token {git_pat}\",\n",
87+
" \"Accept\": \"application/vnd.github.v3+json\"\n",
88+
" }\n",
89+
"\n",
90+
" print(f\"Downloading ZIP from {zip_url}...\")\n",
91+
" response = requests.get(zip_url, headers=headers, stream=True)\n",
92+
" response.raise_for_status()\n",
93+
"\n",
94+
" # Extract the ZIP content\n",
95+
" with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:\n",
96+
" \n",
97+
" top_level_folder = os.path.commonprefix(zip_ref.namelist())\n",
98+
" # Extract all files\n",
99+
" zip_ref.extractall(aidp_path)\n",
100+
" print(\"Repository downloaded and extracted successfully.\")\n",
101+
"\n",
102+
"except requests.exceptions.RequestException as e:\n",
103+
" print(f\"Error downloading repository: {e}\")\n",
104+
"except zipfile.BadZipFile:\n",
105+
" print(\"Downloaded file is not a valid ZIP file.\")\n",
106+
"except Exception as e:\n",
107+
" print(f\"An unexpected error occurred: {e}\")\n"
108+
]
109+
}
110+
],
111+
"metadata": {
112+
"Last_Active_Cell_Index": 2,
113+
"kernelspec": {
114+
"display_name": "python3",
115+
"name": "notebook"
116+
},
117+
"language_info": {
118+
"file_extension": ".py",
119+
"mimetype": "text/x-python",
120+
"name": "python"
75121
}
76-
]
77-
}
122+
},
123+
"nbformat": 4,
124+
"nbformat_minor": 5
125+
}

0 commit comments

Comments
 (0)