File size: 4,259 Bytes
d45258a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"id": "7a478c86",
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-31T01:55:12.877222Z",
"start_time": "2023-07-31T01:55:12.874203Z"
}
},
"outputs": [],
"source": [
"import requests\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "61571547",
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-31T01:57:23.295679Z",
"start_time": "2023-07-31T01:57:23.292514Z"
}
},
"outputs": [],
"source": [
"t = 2314"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5d7eda84",
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-31T01:56:12.033568Z",
"start_time": "2023-07-31T01:56:12.025127Z"
}
},
"outputs": [],
"source": [
"def download_java_files(url, path):\n",
" global t\n",
" # Send GET request to retrieve the folder contents\n",
" response = requests.get(url, params={\"ref\": branch})\n",
" if response.status_code == 200:\n",
" # Parse the response JSON\n",
" contents = response.json()\n",
"\n",
" for item in contents:\n",
" if item[\"type\"] == \"file\" and item[\"name\"].endswith(\".java\"):\n",
" # Download Java file\n",
" download_url = item[\"download_url\"]\n",
" file_name = \"train_\"+str(t)\n",
" output_file_path = f\"Desktop/MITACS/Dataset/inp-txt/{file_name}\"\n",
"\n",
" # Send GET request to download the file content\n",
" file_content = requests.get(download_url).text\n",
"\n",
" # Save the file to the output directory\n",
" with open(output_file_path, \"w\") as output_file:\n",
" output_file.write(file_content)\n",
"\n",
" print(f\"Downloaded: {file_name}\")\n",
" t+=1\n",
" elif item[\"type\"] == \"dir\":\n",
" # Recursively navigate into subfolders\n",
" subfolder_url = item[\"url\"]\n",
" subfolder_path = f\"{path}/{item['name']}\"\n",
" download_java_files(subfolder_url, subfolder_path)\n",
" else:\n",
" print(\"Failed to retrieve folder contents.\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "dafd2b43",
"metadata": {
"ExecuteTime": {
"end_time": "2023-07-31T01:59:48.822445Z",
"start_time": "2023-07-31T01:59:48.667420Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Failed to retrieve folder contents.\n",
"2314\n"
]
}
],
"source": [
"# GitHub repository details\n",
"repo = \"leakcanary\"\n",
"owner = \"square\"\n",
"branch = \"main\" # Specify the branch you want to download from\n",
"output_directory = \"DesktopDataset/inp-txt\" # Specify the directory to save the downloaded files\n",
"# API endpoint to get the list of files in the repository\n",
"url = f\"https://api.github.com/repos/{owner}/{repo}/contents\"\n",
"download_java_files(url, output_directory)\n",
"print(t)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f51e193d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10 (tensorflown)",
"language": "python",
"name": "tensorflown"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|