In [15]:
'''
Important requires https://github.com/andycasey/ads
Getting Started
You'll need an API key from NASA ADS labs. Sign up for the newest version of ADS search here, then you can apply for API access by filling out this form.
When you get your API key, save it to a file called ~/.ads/dev_key or save it as an environment variable named ADS_DEV_KEY
From a terminal type pip install ads (or if you must, use easy_install ads)
'''
import ads
import cPickle as pickle
import urllib
In [44]:
#Query ADS see https://github.com/andycasey/ads for the api
query = ads.query("10.1093/mnras/stu129", database='astronomy', rows=1)
#Make a list of formated dictionaries to send to the pickle file
papers = []
paper_dicts = []
count = 0
for paper in query:
dct = {'authors':paper.author, 'first_author_affiliation':paper.aff[0],
'number_of_citations':paper.citation_count, 'title':paper.title,
'keywords':paper.keyword, 'arXiv_cat':u"None"
}
arXiv_id = u'None'
for j in paper.identifier:
if 'arXiv:' in j:
arXiv_id = j.strip('arXiv:')
if arXiv_id != u'None':
url = 'http://export.arxiv.org/api/query?search_query={}'.format(arXiv_id)
data = urllib.urlopen(url).readlines()
#print data
for i in data :
if 'category term=' in i :
#print i
arXiv_id = i.split()[1].strip("term=\"")
print arXiv_id
dct['arXiv_cat'] = arXiv_id
print dct['arXiv_cat']
paper_dicts.append(dct)
papers.append(paper)
#We can pickle that!
#output = file('papers.pkl', 'w')
#pickle.dump(paper_dicts, output)
#output.close()
In [45]:
print paper_dicts
In [41]:
print papers[0]
In [ ]:
In [29]:
bob
In [53]:
query = ads.query("Morehead, Robert C.", database='astronomy', sort='cited', rows=20)
for paper in query:
print paper.citation_count, paper.title[0]
In [ ]: