isogeo_pysdk.utils module
Complementary set of utils to use with Isogeo API.
- class isogeo_pysdk.utils.IsogeoUtils(proxies={})
Bases:
object
Complementary set of utilitary methods and functions to make it easier using Isogeo API.
- API_URLS = {'prod': 'v1.api.isogeo.com', 'qa': 'v1.api.qa.isogeo.com'}
- APP_URLS = {'prod': 'https://app.isogeo.com', 'qa': 'https://qa-isogeo-app.azurewebsites.net'}
- CSW_URLS = {'prod': 'https://services.api.isogeo.com/', 'qa': 'http://services.api.qa.isogeo.com'}
- MNG_URLS = {'prod': 'https://manage.isogeo.com', 'qa': 'https://qa-isogeo-manage.azurewebsites.net'}
- OC_URLS = {'prod': 'https://open.isogeo.com', 'qa': 'https://qa-isogeo-open.azurewebsites.net'}
- WEBAPPS = {'csw_getcap': {'args': ('share_id', 'share_token'), 'url': 'https://services.api.isogeo.com/ows/s/{share_id}/{share_token}?service=CSW&version=2.0.2&request=GetCapabilities'}, 'csw_getrec': {'args': ('md_uuid_urn', 'share_id', 'share_token'), 'url': 'https://services.api.isogeo.com/ows/s/{share_id}/{share_token}?service=CSW&version=2.0.2&request=GetRecordById&id={md_uuid_urn}&elementsetname=full&outputSchema=http://www.isotc211.org/2005/gmd'}, 'csw_getrecords': {'args': ('share_id', 'share_token'), 'url': 'https://services.api.isogeo.com/ows/s/{share_id}/{share_token}?service=CSW&version=2.0.2&request=GetRecords&ResultType=results&ElementSetName=brief&maxRecords=20&OutputFormat=application/xml&OutputSchema=http://www.opengis.net/cat/csw/2.0.2&namespace=xmlns(csw=http://www.opengis.net/cat/csw/2.0.2)&TypeNames=csw:Record&startPosition=1'}, 'oc': {'args': ('md_id', 'share_id', 'share_token'), 'url': 'https://{oc_url}/s/{share_id}/{share_token}/r/{md_id}'}, 'pixup_portal': {'args': ('md_id', 'portal_url'), 'url': 'http://{portal_url}/?muid={md_id}'}}
- classmethod cache_clearer(only_already_hit=1)
Clear all LRU cached functions.
- Parameters
only_already_hit (bool) – option to clear cache only for functions which have been already hit. Defaults to True.
- classmethod convert_octets(octets)
Convert a mount of octets in readable size.
- Parameters
octets (int) – mount of octets to convert
- Example
>>> IsogeoUtils.convert_octets(1024) "1ko"
- Return type
- classmethod convert_uuid(in_uuid=<class 'str'>, mode=0)
Convert a metadata UUID to its URI equivalent. And conversely.
- classmethod credentials_loader(in_credentials='client_secrets.json')
Loads API credentials from a file, JSON or INI.
- Parameters
in_credentials (str) – path to the credentials file. By default, ./client_secrets.json
- Return type
- Returns
a dictionary with credentials (ID, secret, URLs, platform…)
- Example
api_credentials = IsogeoUtils.credentials_loader("./_auth/client_secrets.json") pprint.pprint(api_credentials) >>> { 'auth_mode': 'group', 'client_id': 'python-minimalist-sdk-test-uuid-1a2b3c4d5e6f7g8h9i0j11k12l', 'client_secret': 'application-secret-1a2b3c4d5e6f7g8h9i0j11k12l13m14n15o16p17Q18rS', 'kind': None, 'platform': 'prod', 'scopes': ['resources:read'], 'staff': None, 'type': None, 'uri_auth': 'https://id.api.isogeo.com/oauth/authorize', 'uri_base': 'https://api.isogeo.com', 'uri_redirect': None, 'uri_token': 'https://id.api.isogeo.com/oauth/token' }
- classmethod encoded_words_to_text(in_encoded_words)
Pull out the character set, encoding, and encoded text from the input encoded words. Next, it decodes the encoded words into a byte string, using either the quopri module or base64 module as determined by the encoding. Finally, it decodes the byte string using the character set and returns the result.
See:
- Parameters
in_encoded_words (str) – base64 or quori encoded character string.
- get_edit_url(metadata, tab='identification')
Returns the edition URL of a metadata.
- get_isogeo_version(component='api', prot='https')
Get Isogeo components versions. Authentication not required.
- Parameters
component (str) –
which platform component. Options:
api [default]
db
app
- get_request_base_url(route, prot='https')
Build the request url for the specified route.
- classmethod get_url_base_from_url_token(url_api_token='https://id.api.isogeo.com/oauth/token')
Returns the Isogeo API root URL (not included into credentials file) from the token or the auth URL (always included).
- Parameters
str (url_api_token) – url to Isogeo API ID token generator
- Return type
- Example
IsogeoUtils.get_url_base_from_url_token() >>> "https://api.isogeo.com" IsogeoUtils.get_url_base_from_url_token(url_api_token="https://id.api.qa.isogeo.com/oauth/token") >>> "https://api.qa.isogeo.com"
- get_view_url(webapp='oc', **kwargs)
Constructs the view URL of a metadata.
- classmethod guess_platform_from_url(url='https://api.isogeo.com/')
Returns the Isogeo platform from a given URL.
- Parameters
str (url) – URL string to guess from
- Return type
- Returns
“prod” or “qa” or “unknown”
- Example
IsogeoUtils.guess_platform_from_url("https://api.isogeo.com") >>> "prod" IsogeoUtils.guess_platform_from_url("https://api.qa.isogeo.com") >>> "qa" IsogeoUtils.guess_platform_from_url("https://api.isogeo.ratp.local") >>> "unknown"
- classmethod hlpr_datetimes(in_date, try_again=1)
Helper to handle differnts dates formats. See: https://github.com/isogeo/isogeo-api-py-minsdk/issues/85
- Parameters
- Returns
a correct datetime object
- Return type
datetime
- Example
# for an event date IsogeoUtils.hlpr_datetimes"2018-06-04T00:00:00+00:00") >>> 2018-06-04 00:00:00 # for a metadata creation date with 6 digits as milliseconds IsogeoUtils.hlpr_datetimes"2019-05-17T13:01:08.559123+00:00") >>> 2019-05-17 13:01:08.559123 # for a metadata creation date with more than 6 digits as milliseconds IsogeoUtils.hlpr_datetimes"2019-06-13T16:21:38.1917618+00:00") >>> 2019-06-13 16:21:38.191761
- lang = 'fr'
- classmethod pages_counter(total, page_size=100)
Simple helper to handle pagination. Returns the number of pages for a given number of results.
- register_webapp(webapp_name, webapp_args, webapp_url)
Register a new WEBAPP to use with the view URL builder.
- Parameters
webapp_name (str) – name of the web app to register
webapp_args (list) – dynamic arguments to complete the URL. Typically ‘md_id’.
webapp_url (str) – URL of the web app to register with args tags to replace. Example: ‘https://www.ppige-npdc.fr/portail/geocatalogue?uuid={md_id}’
- set_base_url(platform='prod', dict_urls={})
Set Isogeo base URLs according to platform.
- classmethod set_lang_and_locale(lang)
Set requests language and the matching locale.
- Parameters
lang (str) – language code to set API localization (“en” or “fr”). Defaults to ‘fr’.
- tags_to_dict(tags=<class 'dict'>, prev_query=<class 'dict'>, duplicated='rename')
Reverse search tags dictionary to values as keys. Useful to populate filters comboboxes for example.
- Parameters
tags (dict) – tags dictionary from a search request
prev_query (dict) – query parameters returned after a search request. Typically search.get(“query”).
duplicated (str) –
what to do about duplicated tags label. Values:
ignore - last tag parsed survives
merge - add duplicated in value as separated list (sep = ‘||’)
rename [default] - if duplicated tag labels are part of different workgroup, so the tag label is renamed with workgroup.