-
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.
- Loading branch information
1 parent
2fc18a8
commit 6f57f31
Showing
7 changed files
with
53 additions
and
52 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
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,45 +1,16 @@ | ||
"""Search.""" | ||
import json | ||
from urllib import request as url | ||
|
||
from pygleif.const import ALLOW_ATTR_REGISTRATION_STATUS, URL_SEARCH | ||
|
||
from pygleif.api import SearchResponse | ||
from pygleif.const import URL_SEARCH | ||
|
||
from .utils import load_json | ||
|
||
|
||
class Search: | ||
"""Class to use the search form of the GLEIF web site.""" | ||
|
||
def __init__(self, orgnr=None): | ||
def __init__(self, orgnr: str) -> None: | ||
"""Init class.""" | ||
# Allow searching using organisation number | ||
self.orgnr = orgnr | ||
|
||
@property | ||
def json_data(self): | ||
"""Get raw data from the service.""" | ||
return url.urlopen(URL_SEARCH + url.quote(self.orgnr)) | ||
|
||
@property | ||
def raw(self): | ||
"""Return parsed json.""" | ||
return json.loads(self.json_data.read().decode("UTF-8")) | ||
|
||
@property | ||
def valid_record(self): | ||
"""Loop through data to find a valid record. Return first valid.""" | ||
for d in self.raw["data"]: | ||
|
||
# We're not very greedy here, but it seems some records have | ||
# lapsed even through the issuer is active | ||
if ( | ||
d["attributes"]["registration"]["status"] | ||
in ALLOW_ATTR_REGISTRATION_STATUS | ||
): | ||
return d["attributes"] | ||
|
||
@property | ||
def lei(self): | ||
"""Return the LEI code.""" | ||
try: | ||
return self.valid_record["lei"] | ||
except (IndexError, TypeError): | ||
return None | ||
json_data = load_json(search_url=URL_SEARCH, search_string=orgnr) | ||
self.response = SearchResponse(**json_data) |
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