Skip to content

Commit

Permalink
added apikey region support
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJeremyHobbs committed Jun 4, 2019
1 parent 1cb6f29 commit c9a855a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ It is a portable app that can run locally on your desktop or else a usb flash dr
Check the [releases](https://github.com/MrJeremyHobbs/RoboReturns/releases) tab above for a downloadable zip.

## Documentation
Documentation is included. You can also view it by clicking [here](https://github.com/MrJeremyHobbs/RoboReturns/blob/master/docs/Manual.pdf).
Documentation is included. You can also view it by clicking [here](https://github.com/MrJeremyHobbs/RoboReturns/blob/master/docs/Manual.pdf).
10 changes: 6 additions & 4 deletions RoboReturns.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def main(*args):
barcode = barcode[:-config.suffix_trim]

# get information from item record in Alma
item = alma.item_record(barcode, config.apikey)
item = alma.item_record(barcode, config.apikey, config.apikey_region)
if item.found == False:
counter += 1
gui.insert_text(counter, (barcode, "n/a", "Error", item.error_msg),
Expand All @@ -92,9 +92,10 @@ def main(*args):

# return item
scan_return = alma.ret()
scan_return.post(config.apikey, config.library, config.circ_desk,
config.register_in_house_use, item.mms_id,
item.holding_id, item.pid, item.xml)
scan_return.post(config.apikey, config.apikey_region, config.library,
config.circ_desk,
config.register_in_house_use, item.mms_id,
item.holding_id, item.pid, item.xml)
if scan_return.successful == False:
counter += 1
gui.insert_text(counter, (barcode, item.title, "Error",
Expand Down Expand Up @@ -165,6 +166,7 @@ def __init__(self, configfile):
self.delete_barcode_file = c_dict['misc']['delete_barcode_file']

self.key = c_dict['apikey']['key']
self.apikey_region = c_dict['apikey']['region'].lower()

self.download_directory = c_dict['spreadsheet']['spreadsheet_directory'].replace('\\', '//')
self.barcode_column_header = c_dict['spreadsheet']['barcode_column_header']
Expand Down
15 changes: 9 additions & 6 deletions alma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

# classes #####################################################################
class item_record:
def __init__(self, barcode, apikey):
def __init__(self, barcode, apikey, apikey_region):
self.item_record = item_record

# generate request url, escape special characters
url = f"https://api-na.hosted.exlibrisgroup.com/almaws/v1/items?view=label&item_barcode={barcode}&apikey={apikey}"
url = f"https://api-{apikey_region}.hosted.exlibrisgroup.com/almaws/v1/items?view=label&item_barcode={barcode}&apikey={apikey}"
encoded_url = quote(url, safe='/:?=&', encoding=None, errors=None)
self.r = requests.get(encoded_url)

Expand Down Expand Up @@ -110,7 +110,7 @@ class ret:
def __init__(self):
self.ret = ret

def post(self, apikey, library, circ_desk, register_in_house_use, mms_id, holding_id, item_pid, xml):
def post(self, apikey, apikey_region, library, circ_desk, register_in_house_use, mms_id, holding_id, item_pid, xml):
headers = {
'Content-Type': 'application/xml',
'Charset':'UTF-8',
Expand All @@ -124,16 +124,19 @@ def post(self, apikey, library, circ_desk, register_in_house_use, mms_id, holdin
'register_in_house_use': register_in_house_use,
}

base_url = 'https://api-na.hosted.exlibrisgroup.com/almaws/v1'
base_url = f'https://api-{apikey_region}.hosted.exlibrisgroup.com/almaws/v1'
return_url = f"{base_url}/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}"

r = requests.post(return_url, data=xml.encode('utf-8'), headers=headers, params=params)
xml = r.text
dict = xmltodict.parse(xml)

# normalize additional info
self.additional_info = dict['item']['additional_info']
self.additional_info = self.additional_info.replace("Item's destination is:", "Destination:")
try:
self.additional_info = dict['item']['additional_info']
self.additional_info = self.additional_info.replace("Item's destination is:", "Destination:")
except:
self.additional_info = ""

# successful?
if r.status_code != 200:
Expand Down
17 changes: 9 additions & 8 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
[misc]
version=3.1
version=3.2
delete_barcode_file=true

[apikey]
;NOTE: accepts either a plain-text apikey or an environmental variable key name
;NOTE: permissions needed: BIBS (read/write)
key=ROBORETURNS_KEY
NOTE: NA, EU, AP, CA, CN
region=NA

[spreadsheet]
;NOTE: directory must have ending "\"
spreadsheet_directory=E:\Scanned Barcodes\
spreadsheet_directory=E:\Spreadsheet_Directory\
;NOTE leave blank if file has no headers
barcode_column_header=BARCODE
barcode_column_header=

[alma]
library = MAIN
library = CPSLO_MAIN
circ_desk = DEFAULT_CIRC_DESK
register_in_house_use=true

[barcodes]
;NOTE: number of chars to trim off front(prefix) and end(suffix) of barcode
prefix_trim=0
suffix_trim=0
prefix_trim=1
suffix_trim=1

[log]
;NOTE: directory must have ending "\"
log_directory=C:\Users\username\Desktop\
log_directory=C:\Users\user\Desktop\
2 changes: 0 additions & 2 deletions full_make_exe.bat

This file was deleted.

0 comments on commit c9a855a

Please sign in to comment.