Upload download_arxiv_data.py
Browse files- download_arxiv_data.py +76 -0
download_arxiv_data.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# coding: utf-8
|
| 3 |
+
|
| 4 |
+
# If arxiv is not installed:
|
| 5 |
+
#
|
| 6 |
+
# ```bash
|
| 7 |
+
# pip install arxiv
|
| 8 |
+
# ```
|
| 9 |
+
|
| 10 |
+
# In[1]:
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
import json
|
| 14 |
+
import arxiv
|
| 15 |
+
import logging
|
| 16 |
+
from tqdm import tqdm
|
| 17 |
+
|
| 18 |
+
def get_info(result):
|
| 19 |
+
d = {'title': result.title, 'published': str(result.published.date()),
|
| 20 |
+
'authors': [a.name for a in result.authors],
|
| 21 |
+
'summary': result.summary, 'link': result.entry_id}
|
| 22 |
+
return d
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# In[2]:
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
num_papers = 50000
|
| 29 |
+
# logging.basicConfig(level=logging.INFO) # if you have more details about process
|
| 30 |
+
|
| 31 |
+
client = arxiv.Client(
|
| 32 |
+
page_size = 10000,
|
| 33 |
+
delay_seconds = 60,
|
| 34 |
+
num_retries = 5
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
search = arxiv.Search(
|
| 38 |
+
query = "Generative modeling",
|
| 39 |
+
max_results = num_papers,
|
| 40 |
+
sort_by= arxiv.SortCriterion.Relevance,
|
| 41 |
+
sort_order=arxiv.SortOrder.Descending
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# In[3]:
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
data = []
|
| 49 |
+
while len(data) < num_papers:
|
| 50 |
+
for result in tqdm(client.results(search), total=num_papers):
|
| 51 |
+
data.append(get_info(result))
|
| 52 |
+
if len(data) >= num_papers:
|
| 53 |
+
break
|
| 54 |
+
# except arxiv.UnexpectedEmptyPageError:
|
| 55 |
+
# print(f'Exception on {len(data)} records')
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# In[4]:
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
print(f'finally: {len(data)} entries')
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# In[5]:
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
with open('arxiv_sample.json', 'w') as fp:
|
| 68 |
+
json.dump(data, fp)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# Pack and check results
|
| 72 |
+
#
|
| 73 |
+
# ```bash
|
| 74 |
+
# tar -zcvf arxiv_sample.tar.gz arxiv_sample.json
|
| 75 |
+
# ls -lh arxiv*
|
| 76 |
+
# ```
|