-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_article_download.py
45 lines (36 loc) · 1.29 KB
/
random_article_download.py
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
import os
import urllib
from datetime import datetime
# articles import
from mnras import *
from aanda import *
from iop import *
def download_pdf(pdf_url, output_pdf=None):
if output_pdf is None:
output_pdf = pdf_url.split('/')[-1]
try:
urllib.urlretrieve(pdf_url, output_pdf)
except:
print 'Problem downloading file: '+str(pdf_url)
output_dir = '~/AAOD'
os.system('mkdir '+output_dir)
os.chdir(os.path.expanduser(output_dir))
print 'Script run at '+str(str(datetime.now()))
# get MNRAS article
print 'Searching for a random MNRAS article'
pdf_mnras = MNRAS().get_random_article()
print ' downloading article: ' + pdf_mnras
download_pdf(pdf_mnras)
# get AANDA article
print 'Searching for a random AANDA article'
pdf_aanda = AANDA().get_random_article()
print ' downloading article: ' + pdf_aanda
download_pdf(pdf_aanda)
# get articles for different journals hosted by IOP SCIENCE
for j_str in ['PASP', 'ApJ', 'ApJL', 'AJ', 'ApJS']:
print 'Searching for a random '+j_str+' article'
pdf_iop = IOP_SCIENCE(journal=j_str).get_random_article()
print ' downloading article: ' + pdf_iop
output_name = '_'.join(pdf_iop.split('/')[-4:-1])+'.pdf' # replace generic pdf name
download_pdf(pdf_iop, output_pdf=output_name)
print 'Finished at '+str(str(datetime.now()))