-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from metaodi/develop
Release 2.0.0
- Loading branch information
Showing
32 changed files
with
611 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ sruthi.egg-info | |
*.pyc | ||
*.swp | ||
.coverage | ||
pyenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
import requests | ||
from sruthi import Client | ||
|
||
# create authenticated session | ||
user = os.getenv("CATALOG_USER") | ||
pw = os.getenv("CATALOG_PASS") | ||
session = requests.Session() | ||
session.auth = (user, pw) | ||
|
||
# pass authenticated session to client | ||
sru_client = Client("https://suche.staatsarchiv.djiktzh.ch/SRU/", session=session) | ||
|
||
# get records for query | ||
records = sru_client.searchretrieve(query="Zürich") | ||
print(records) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
from sruthi import Client | ||
|
||
# create a new client and call explain() | ||
sru_client = Client('https://suche.staatsarchiv.djiktzh.ch/SRU/') | ||
sru_client = Client("https://suche.staatsarchiv.djiktzh.ch/SRU/") | ||
info = sru_client.explain() | ||
|
||
for name, details in info.schema.items(): | ||
print(f"This SRU endpoint supports the metadata schema {details['title']}.") | ||
|
||
# configure the maximum records based on the config | ||
try: | ||
sru_client.maximum_records = info.config['maximumRecords'] | ||
sru_client.maximum_records = info.config["maximumRecords"] | ||
print(f"Set maximum_records to {sru_client.maximum_records}.") | ||
except KeyError: | ||
print("Config `maximum_records` not available, keep original value") | ||
|
||
# get records for query | ||
records = sru_client.searchretrieve(query='Zürich') | ||
records = sru_client.searchretrieve(query="Zürich") | ||
|
||
# display 5 records | ||
print('') | ||
print('First 5 results for `Zürich`') | ||
print("") | ||
print("First 5 results for `Zürich`") | ||
for r in records[:5]: | ||
print("* ", r['title']) | ||
print("* ", r["title"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import requests | ||
import sruthi | ||
from pprint import pprint | ||
|
||
|
||
def print_url(r, *args, **kwargs): | ||
print(r.url) | ||
|
||
|
||
# create session with custom paramter session | ||
session = requests.Session() | ||
|
||
# here some example of how a session can be used to customize parameters, settings etc. | ||
session.params = {"x-collection": "GGC"} # add custom request parameter | ||
session.verify = False # disable SSL verfications | ||
session.hooks["response"].append(print_url) # add custom hook | ||
|
||
# pass custom session to client | ||
sru_client = sruthi.Client("https://jsru.kb.nl/sru", session=session) | ||
|
||
# get records for query | ||
records = sru_client.searchretrieve(query="gruninger") | ||
pprint(records) | ||
print("---") | ||
pprint(records[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import sruthi | ||
import sys | ||
|
||
LOC_BASE = 'http://lx2.loc.gov:210/LCDB?' | ||
LOC_BASE = "http://lx2.loc.gov:210/LCDB?" | ||
|
||
|
||
def loc_search(isbn, sru_base): | ||
loc_lcc = None | ||
try: | ||
records = sruthi.searchretrieve(sru_base, query=isbn) | ||
record = records[0] | ||
fields = record.get('datafield', []) | ||
fields = record.get("datafield", []) | ||
for field in fields: | ||
if field['tag'] != '050': | ||
if field["tag"] != "050": | ||
continue | ||
if len(field.get('subfield', [])) > 0: | ||
loc_lcc = (field['subfield'][0]['text']) | ||
if len(field.get("subfield", [])) > 0: | ||
loc_lcc = field["subfield"][0]["text"] | ||
break | ||
except Exception as e: | ||
print("Error: %s" % e, file=sys.stderr) | ||
return None | ||
return loc_lcc | ||
|
||
|
||
isbn = '0062509470' | ||
isbn = "0062509470" | ||
result = loc_search(isbn, LOC_BASE) | ||
print(f"Tag 050 of ISBN '{isbn}': {result}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.