File size: 9,232 Bytes
a53f410 |
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import json\n",
"from pandas import json_normalize\n",
"import requests\n",
"from pathlib import Path\n",
"from multiprocessing.pool import ThreadPool as Pool\n",
"import codecs\n",
"import random\n",
"import re"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"URL_BASE = \"https://arxiv.org/pdf/\"\n",
"PDF_PATH = 'PDF'\n",
"TXT_PATH= 'TXT'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Arxiv\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>title</th>\n",
" <th>abstract</th>\n",
" <th>Text</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0704.0001</td>\n",
" <td>Calculation of prompt diphoton production cros...</td>\n",
" <td>A fully differential calculation in perturba...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0704.0002</td>\n",
" <td>Sparsity-certifying Graph Decompositions</td>\n",
" <td>We describe a new algorithm, the $(k,\\ell)$-...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0704.0003</td>\n",
" <td>The evolution of the Earth-Moon system based o...</td>\n",
" <td>The evolution of Earth-Moon system is descri...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0704.0004</td>\n",
" <td>A determinant of Stirling cycle numbers counts...</td>\n",
" <td>We show that a determinant of Stirling cycle...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0704.0005</td>\n",
" <td>From dyadic $\\Lambda_{\\alpha}$ to $\\Lambda_{\\a...</td>\n",
" <td>In this paper we show how to compute the $\\L...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1996</th>\n",
" <td>0704.1997</td>\n",
" <td>Query on Negative Temperature, Internal Intera...</td>\n",
" <td>After negative temperature is restated, we f...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1997</th>\n",
" <td>0704.1998</td>\n",
" <td>Absence of the Fifth Force Problem in a Model ...</td>\n",
" <td>A scale invariant model containing dilaton $...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1998</th>\n",
" <td>0704.1999</td>\n",
" <td>Dark matter caustics and the enhancement of se...</td>\n",
" <td>Cold dark matter haloes are populated by cau...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1999</th>\n",
" <td>0704.2000</td>\n",
" <td>Search for a Higgs boson produced in associati...</td>\n",
" <td>We describe a search for the standard model ...</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000</th>\n",
" <td>0704.2001</td>\n",
" <td>Geometry of Parallelizable Manifolds in the Co...</td>\n",
" <td>In this paper, we deal with a generalization...</td>\n",
" <td></td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>2001 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" id title \\\n",
"0 0704.0001 Calculation of prompt diphoton production cros... \n",
"1 0704.0002 Sparsity-certifying Graph Decompositions \n",
"2 0704.0003 The evolution of the Earth-Moon system based o... \n",
"3 0704.0004 A determinant of Stirling cycle numbers counts... \n",
"4 0704.0005 From dyadic $\\Lambda_{\\alpha}$ to $\\Lambda_{\\a... \n",
"... ... ... \n",
"1996 0704.1997 Query on Negative Temperature, Internal Intera... \n",
"1997 0704.1998 Absence of the Fifth Force Problem in a Model ... \n",
"1998 0704.1999 Dark matter caustics and the enhancement of se... \n",
"1999 0704.2000 Search for a Higgs boson produced in associati... \n",
"2000 0704.2001 Geometry of Parallelizable Manifolds in the Co... \n",
"\n",
" abstract Text \n",
"0 A fully differential calculation in perturba... \n",
"1 We describe a new algorithm, the $(k,\\ell)$-... \n",
"2 The evolution of Earth-Moon system is descri... \n",
"3 We show that a determinant of Stirling cycle... \n",
"4 In this paper we show how to compute the $\\L... \n",
"... ... ... \n",
"1996 After negative temperature is restated, we f... \n",
"1997 A scale invariant model containing dilaton $... \n",
"1998 Cold dark matter haloes are populated by cau... \n",
"1999 We describe a search for the standard model ... \n",
"2000 In this paper, we deal with a generalization... \n",
"\n",
"[2001 rows x 4 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = pd.read_json('ARxiv/arxiv-metadata-oai-snapshot.json',lines=True, chunksize=2001,dtype={'id':'str'})\n",
"df = None\n",
"for i in data:\n",
" df = i \n",
" print(type(i))\n",
" break\n",
"df = df[['id','title','abstract']]\n",
"df.insert(3, \"Text\", \"\") \n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def GetFileURL(file_id):\n",
" url = URL_BASE+file_id\n",
" r = requests.get(url, stream=True) \n",
" filename = Path(PDF_PATH+'/'+file_id+'.pdf')\n",
" response = requests.get(url)\n",
" filename.write_bytes(response.content)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"pool_size = 16 \n",
"def worker(file):\n",
" try:\n",
" GetFileURL(file)\n",
" except:\n",
" print('error with item '+ file)\n",
" try:\n",
" with codecs.open(PDF_PATH+'/log.txt', 'a') as the_file: \n",
" the_file.writelines(str(file)+\"\\n\")\n",
" except:\n",
" print('error en log '+ file)\n",
"def get_ids(iteracion,batch=100): \n",
" inicio = int(iteracion*batch)\n",
" filesId = data[inicio :inicio + batch]['id']\n",
" return filesId\n",
"\n",
"pool = Pool(pool_size)\n",
"filesId = get_ids(19)\n",
"for file in filesId:\n",
" pool.apply_async(worker, (file,))\n",
"\n",
"pool.close()\n",
"pool.join()"
]
}
],
"metadata": {
"interpreter": {
"hash": "3f7e9d73c32ad96f75174922c475a50b168aad887cbaa14717912a88f31d3802"
},
"kernelspec": {
"display_name": "Python 3.9.7 ('tf-gpu')",
"language": "python",
"name": "python3"
},
"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.9.7"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|