Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
if indicator:
if source or topic:
raise ValueError(INDIC_ERROR)
query_url = "/".join((INDICATOR_URL, parse_value_or_iterable(indicator)))
elif source:
if topic:
raise ValueError(INDIC_ERROR)
query_url = "/".join(
(SOURCES_URL, parse_value_or_iterable(source), "indicators")
)
elif topic:
query_url = "/".join((TOPIC_URL, parse_value_or_iterable(topic), "indicators"))
else:
query_url = INDICATOR_URL
return WBSearchResult(fetcher.fetch(query_url, cache=cache))
def id_only_query(query_url, query_id, cache):
"""
Retrieve information when ids are the only arguments
:query_url: the base url to use for the query
:query_id: an id or sequence of ids
:cache: use the cache
:returns: WBSearchResult containing dictionary objects describing results
"""
if query_id:
query_url = "/".join((query_url, parse_value_or_iterable(query_id)))
return WBSearchResult(fetcher.fetch(query_url))
def search_countries(query, incomelevel=None, lendingtype=None, cache=True):
"""
Search countries by name. Very simple search.
:query: the string to match against country names
:incomelevel: if present, search only the matching incomelevel
:lendingtype: if present, search only the matching lendingtype
:cache: use the cache
:returns: WBSearchResult containing dictionary objects representing
countries
"""
countries = get_country(
incomelevel=incomelevel, lendingtype=lendingtype, cache=cache
)
pattern = re.compile(query, re.IGNORECASE)
return WBSearchResult(i for i in countries if pattern.search(i["name"]))
def search_indicators(query, source=None, topic=None, cache=True):
"""
Search indicators for a certain regular expression. Only one of source or
topic can be specified. In interactive mode, will return None and print ids
and names unless suppress_printing is True.
:query: the term to match against indicator names
:source: if present, id of desired source
:topic: if present, id of desired topic
:cache: use the cache
:returns: WBSearchResult containing dictionary objects representing search
indicators
"""
indicators = get_indicator(source=source, topic=topic, cache=cache)
pattern = re.compile(query, re.IGNORECASE)
return WBSearchResult(i for i in indicators if pattern.search(i["name"]))