Skip to content

Commit

Permalink
Merge pull request #54 from seasidesparrow/issn_endpoint.2023Mar13
Browse files Browse the repository at this point in the history
New ISSN search endpoint (Fulfills Issue #53)
  • Loading branch information
seasidesparrow authored Mar 20, 2023
2 parents 0d4c5ba + e136ef3 commit d523e43
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
3 changes: 2 additions & 1 deletion journalsservice/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import
from werkzeug.serving import run_simple
from .views import Summary, Journal, Holdings, Refsource
from .views import Summary, Journal, Holdings, Refsource, ISSN
from flask_restful import Api
from flask_discoverer import Discoverer
from adsmutils import ADSFlask
Expand All @@ -24,6 +24,7 @@ def create_app(**config):
api.add_resource(Journal, '/journal/<string:journalname>')
api.add_resource(Holdings, '/holdings/<string:bibstem>/<string:volume>')
api.add_resource(Refsource, '/refsource/<string:bibstem>')
api.add_resource(ISSN, '/issn/<string:issn>')

discoverer = Discoverer(app)

Expand Down
42 changes: 37 additions & 5 deletions journalsservice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from journalsdb.models import JournalsMaster, JournalsAbbreviations, JournalsIdentifiers, JournalsPublisher, JournalsRefSource, JournalsTitleHistory, JournalsNames
from journalsservice.adsquery import ADSQuery
import adsmutils
from sqlalchemy import or_
from sqlalchemy import or_, and_

def liken(text):
text_out = re.sub(r'[. ]{1,}', '%', text)
Expand Down Expand Up @@ -58,7 +58,7 @@ def get(self, bibstem):
return result_json, 200
except Exception as err:
return {'Error': 'Summary search failed',
'Error Info': 'Unspecified error. Try again.'}, 500
'Error Info': str(err)}, 500
else:
result_json = {'summary': {}}
return result_json, 200
Expand Down Expand Up @@ -92,7 +92,7 @@ def get(self, journalname):
journal_list.append({"bibstem": dat_master.bibstem, "name": dat_master.journal_name})
except Exception as err:
return {'Error': 'Journal search failed',
'Error Info': 'Unspecified error. Try again.'}, 500
'Error Info': str(err)}, 500

result_json = {'journal': journal_list}
return result_json, 200
Expand All @@ -119,7 +119,7 @@ def get(self, bibstem, volume):
'holdings': holdings}
except Exception as err:
return {'Error': 'Holdings search failed',
'Error Info': 'Unspecified error. Try again.'}, 500
'Error Info': str(err)}, 500
else:
return result, 200

Expand Down Expand Up @@ -148,6 +148,38 @@ def get(self, bibstem):
request_json = json.loads(dat_refsource.refsource_list)
except Exception as err:
return {'Error': 'Refsource search failed',
'Error Info': 'Unspecified error. Try again.'}, 500
'Error Info': str(err)}, 500
return {'refsource': request_json}, 200


class ISSN(Resource):

scopes = []
rate_limit = [1000, 60 * 60 * 24]
decorators = [advertise('scopes', 'rate_limit')]

def get(self, issn):
request_json = {}
if issn:
try:
if len(issn) == 8:
issn = issn[0:4] + "-" + issn[4:]
with current_app.session_scope() as session:
dat_idents = session.query(JournalsIdentifiers).filter(and_(JournalsIdentifiers.id_value==issn, JournalsIdentifiers.id_type.like("ISSN%"))).first()
if dat_idents:
masterid = dat_idents.masterid
id_value = dat_idents.id_value
id_type = dat_idents.id_type
dat_master = session.query(JournalsMaster).filter_by(masterid=masterid).first()
bibstem = dat_master.bibstem
journal_name = dat_master.journal_name
request_json = {'issn': {'ISSN': id_value,
'ISSN_type': id_type,
'bibstem': bibstem,
'journal_name': journal_name}}
except Exception as err:
return {'Error': 'issn search failed',
'Error Info': str(err)}, 500
else:
request_json = {'issn': {}}
return request_json, 200

0 comments on commit d523e43

Please sign in to comment.