SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 012845eb authored by Geert Kapteijns's avatar Geert Kapteijns
Browse files

Start work on new ArxivCaller

parent d8e76207
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ class DOICaller:
request = requests.get(url)
if request.ok:
self.is_valid = True
self._crossref_data = requests.get(url).json()['message']
self._crossref_data = request.json()['message']
else:
self.is_valid = False
......@@ -65,6 +65,48 @@ class DOICaller:
return pub_date
class ArxivCaller:
query_base_url = 'http://export.arxiv.org/api/query?id_list=%s'
def __init__(self, identifier):
self.identifier = identifier
self._call_arxiv()
if self.is_valid:
self._format_data()
def _call_arxiv(self):
url = self.query_base_url % self.identifier
request = requests.get(url)
if request.ok:
self.is_valid = True
self._arxiv_data = feedparser.parse(request.content)
else:
self.is_valid = False
def _format_data(self):
raise NotImplementedError
# metadata = caller.metadata
# pub_title = metadata['entries'][0]['title']
# authorlist = metadata['entries'][0]['authors'][0]['name']
# for author in metadata['entries'][0]['authors'][1:]:
# authorlist += ', ' + author['name']
# arxiv_link = metadata['entries'][0]['id']
# abstract = metadata['entries'][0]['summary']
#
# initialdata = {
# 'type': 'preprint',
# 'metadata': metadata,
# 'pub_title': pub_title,
# 'author_list': authorlist,
# 'arxiv_identifier': identifierform.cleaned_data['identifier'],
# 'arxiv_link': arxiv_link,
# 'pub_abstract': abstract
# }
# I'm going to revamp this whole thing...
class BaseCaller(object):
......@@ -216,12 +258,8 @@ class BaseCaller(object):
return t.render(Context(self.errorvariables))
# class DOICaller(BaseCaller):
# """Perform a DOI lookup for a given identifier."""
# pass
class ArxivCaller(BaseCaller):
class ArxivCallerOld(BaseCaller):
""" Performs an Arxiv article lookup for given identifier """
# State of the caller
......
......@@ -6,7 +6,13 @@ from submissions.models import Submission
class ArxivCallerTest(TestCase):
def setUp(self):
self.valid_arxiv_identifier = '1612.07611v1'
def test_collects_metadata(self):
raise NotImplementedError
class ArxivCallerTestOld(TestCase):
def test_correct_lookup(self):
caller = ArxivCaller(Submission, '1611.09574v1')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment