text
stringlengths
81
112k
Check if dataset exists in HDX and if so, update it Args: update_resources (bool): Whether to update resources. Defaults to True. update_resources_by_name (bool): Compare resource names rather than position in list. Defaults to True. remove_additional_resources (bool): Remov...
Check if dataset exists in HDX and if so, update it, otherwise create it Args: allow_no_resources (bool): Whether to allow no resources. Defaults to False. update_resources (bool): Whether to update resources (if updating). Defaults to True. update_resources_by_name (bool): ...
Searches for datasets in HDX Args: query (Optional[str]): Query (in Solr format). Defaults to '*:*'. configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. page_size (int): Size of page to return. Defaults to 1000. **kwargs:...
Get all dataset names in HDX Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. **kwargs: See below limit (int): Number of rows to return. Defaults to all dataset names. offset (int): Offset in the complete result ...
Get all datasets in HDX Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. page_size (int): Size of page to return. Defaults to 1000. check_duplicates (bool): Whether to check for duplicate datasets. Defaults to True. ...
Get all resources from a list of datasets (such as returned by search) Args: datasets (List[Dataset]): list of datasets Returns: List[hdx.data.resource.Resource]: list of resources within those datasets def get_all_resources(datasets): # type: (List['Dataset']) -> List...
Get dataset date as datetime.datetime object. For range returns start date. Returns: Optional[datetime.datetime]: Dataset date in datetime object or None if no date is set def get_dataset_date_as_datetime(self): # type: () -> Optional[datetime] """Get dataset date as datetime.datet...
Get dataset end date as datetime.datetime object. Returns: Optional[datetime.datetime]: Dataset date in datetime object or None if no date is set def get_dataset_end_date_as_datetime(self): # type: () -> Optional[datetime] """Get dataset end date as datetime.datetime object. ...
Get supplied dataset date as string in specified format. If no format is supplied, an ISO 8601 string is returned. Args: dataset_date (Optional[datetime.datetime]): dataset date in datetime.datetime format date_format (Optional[str]): Date format. None is taken to be ISO 8601....
Get dataset date as string in specified format. For range returns start date. If no format is supplied, an ISO 8601 string is returned. Args: date_format (Optional[str]): Date format. None is taken to be ISO 8601. Defaults to None. Returns: Optional[str]: Dataset date s...
Get dataset date as string in specified format. For range returns start date. If no format is supplied, an ISO 8601 string is returned. Args: date_format (Optional[str]): Date format. None is taken to be ISO 8601. Defaults to None. Returns: Optional[str]: Dataset date s...
Set dataset date from datetime.datetime object Args: dataset_date (datetime.datetime): Dataset date dataset_end_date (Optional[datetime.datetime]): Dataset end date Returns: None def set_dataset_date_from_datetime(self, dataset_date, dataset_end_date=None): ...
Parse dataset date from string using specified format. If no format is supplied, the function will guess. For unambiguous formats, this should be fine. Args: dataset_date (str): Dataset date string date_format (Optional[str]): Date format. If None is given, will attempt to guess...
Set dataset date from string using specified format. If no format is supplied, the function will guess. For unambiguous formats, this should be fine. Args: dataset_date (str): Dataset date string dataset_end_date (Optional[str]): Dataset end date string date_format (...
Set dataset date as a range from year or start and end year. Args: dataset_year (Union[str, int]): Dataset year given as string or int dataset_end_year (Optional[Union[str, int]]): Dataset end year given as string or int Returns: None def set_dataset_year_range(sel...
Get expected update frequency (in textual rather than numeric form) Returns: Optional[str]: Update frequency in textual form or None if the update frequency doesn't exist or is blank. def get_expected_update_frequency(self): # type: () -> Optional[str] """Get expected update freque...
Set expected update frequency Args: update_frequency (str): Update frequency Returns: None def set_expected_update_frequency(self, update_frequency): # type: (str) -> None """Set expected update frequency Args: update_frequency (str): Updat...
Remove a tag Args: tag (str): Tag to remove Returns: bool: True if tag removed or False if not def remove_tag(self, tag): # type: (str) -> bool """Remove a tag Args: tag (str): Tag to remove Returns: bool: True if tag r...
Return the dataset's location Args: locations (Optional[List[str]]): Valid locations list. Defaults to list downloaded from HDX. Returns: List[str]: list of locations or [] if there are none def get_location(self, locations=None): # type: (Optional[List[str]]) -> List[...
Add a country. If an iso 3 code is not provided, value is parsed and if it is a valid country name, converted to an iso 3 code. If the country is already added, it is ignored. Args: country (str): Country to add exact (bool): True for exact matching or False to allow fuzzy match...
Add a list of countries. If iso 3 codes are not provided, values are parsed and where they are valid country names, converted to iso 3 codes. If any country is already added, it is ignored. Args: countries (List[str]): list of countries to add locations (Optional[List[str]]): Va...
Add all countries in a region. If a 3 digit UNStats M49 region code is not provided, value is parsed as a region name. If any country is already added, it is ignored. Args: region (str): M49 region, intermediate region or subregion to add locations (Optional[List[str]]): Valid l...
Add a location which is not a country or region. Value is parsed and compared to existing locations in HDX. If the location is already added, it is ignored. Args: location (str): Location to add exact (bool): True for exact matching or False to allow fuzzy matching. Defaults to ...
Remove a location. If the location is already added, it is ignored. Args: location (str): Location to remove Returns: bool: True if location removed or False if not def remove_location(self, location): # type: (str) -> bool """Remove a location. If the location...
Get the dataset's maintainer. Returns: User: Dataset's maintainer def get_maintainer(self): # type: () -> hdx.data.user.User """Get the dataset's maintainer. Returns: User: Dataset's maintainer """ return hdx.data.user.User.read_from_hdx(sel...
Set the dataset's maintainer. Args: maintainer (Union[User,Dict,str]): Either a user id or User metadata from a User object or dictionary. Returns: None def set_maintainer(self, maintainer): # type: (Union[hdx.data.user.User,Dict,str]) -> None """Set the dat...
Get the dataset's organization. Returns: Organization: Dataset's organization def get_organization(self): # type: () -> hdx.data.organization.Organization """Get the dataset's organization. Returns: Organization: Dataset's organization """ r...
Set the dataset's organization. Args: organization (Union[Organization,Dict,str]): Either an Organization id or Organization metadata from an Organization object or dictionary. Returns: None def set_organization(self, organization): # type: (Union[hdx.data.organizat...
Get any showcases the dataset is in Returns: List[Showcase]: list of showcases def get_showcases(self): # type: () -> List[hdx.data.showcase.Showcase] """Get any showcases the dataset is in Returns: List[Showcase]: list of showcases """ assoc_re...
Get dataset showcase dict Args: showcase (Union[Showcase,Dict,str]): Either a showcase id or Showcase metadata from a Showcase object or dictionary Returns: dict: dataset showcase dict def _get_dataset_showcase_dict(self, showcase): # type: (Union[hdx.data.showcase.Sho...
Add dataset to showcase Args: showcase (Union[Showcase,Dict,str]): Either a showcase id or showcase metadata from a Showcase object or dictionary showcases_to_check (List[Showcase]): list of showcases against which to check existence of showcase. Defaults to showcases containing dataset...
Add dataset to multiple showcases Args: showcases (List[Union[Showcase,Dict,str]]): A list of either showcase ids or showcase metadata from Showcase objects or dictionaries showcases_to_check (List[Showcase]): list of showcases against which to check existence of showcase. Defaults to s...
Remove dataset from showcase Args: showcase (Union[Showcase,Dict,str]): Either a showcase id string or showcase metadata from a Showcase object or dictionary Returns: None def remove_showcase(self, showcase): # type: (Union[hdx.data.showcase.Showcase,Dict,str]) -> None...
Set the dataset to be of type requestable or not Args: requestable (bool): Set whether dataset is requestable. Defaults to True. Returns: None def set_requestable(self, requestable=True): # type: (bool) -> None """Set the dataset to be of type requestable or no...
Return list of filetypes in your data Returns: List[str]: List of filetypes def get_filetypes(self): # type: () -> List[str] """Return list of filetypes in your data Returns: List[str]: List of filetypes """ if not self.is_requestable(): ...
Clean dataset tags according to tags cleanup spreadsheet and return if any changes occurred Returns: Tuple[bool, bool]: Returns (True if tags changed or False if not, True if error or False if not) def clean_dataset_tags(self): # type: () -> Tuple[bool, bool] """Clean dataset tags ...
Set the resource that will be used for displaying QuickCharts in dataset preview Args: resource (Union[hdx.data.resource.Resource,Dict,str,int]): Either resource id or name, resource metadata from a Resource object or a dictionary or position Returns: bool: Returns True if reso...
Create default resource views for all resources in dataset Args: create_datastore_views (bool): Whether to try to create resource views that point to the datastore Returns: None def create_default_views(self, create_datastore_views=False): # type: (bool) -> None ...
Return HDX site username and password Returns: Optional[Tuple[str, str]]: HDX site username and password or None def _get_credentials(self): # type: () -> Optional[Tuple[str, str]] """ Return HDX site username and password Returns: Optional[Tuple[str, s...
Calls the remote CKAN Args: *args: Arguments to pass to remote CKAN call_action method **kwargs: Keyword arguments to pass to remote CKAN call_action method Returns: Dict: The response from the remote CKAN call_action method def call_remoteckan(self, *args, **kwarg...
Overwrite keyword arguments with environment variables Args: **kwargs: See below hdx_url (str): HDX url to use. Overrides hdx_site. hdx_site (str): HDX site to use eg. prod, test. Defaults to test. hdx_key (str): Your HDX key. Ignored if hdx_read_only = True. ...
Create remote CKAN instance from configuration Args: site_url (str): Site url. user_agent (Optional[str]): User agent string. HDXPythonLibrary/X.X.X- is prefixed. user_agent_config_yaml (Optional[str]): Path to YAML user agent configuration. Ignored if user_agent supplied. D...
Set up remote CKAN from provided CKAN or by creating from configuration Args: remoteckan (Optional[ckanapi.RemoteCKAN]): CKAN instance. Defaults to setting one up from configuration. Returns: None def setup_remoteckan(self, remoteckan=None, **kwargs): # type: (Optional...
Set up the HDX configuration Args: configuration (Optional[Configuration]): Configuration instance. Defaults to setting one up from passed arguments. **kwargs: See below user_agent (str): User agent string. HDXPythonLibrary/X.X.X- is prefixed. Must be supplied if remoteckan ...
Create HDX configuration Args: configuration (Optional[Configuration]): Configuration instance. Defaults to setting one up from passed arguments. remoteckan (Optional[ckanapi.RemoteCKAN]): CKAN instance. Defaults to setting one up from configuration. **kwargs: See below ...
Create HDX configuration. Can only be called once (will raise an error if called more than once). Args: configuration (Optional[Configuration]): Configuration instance. Defaults to setting one up from passed arguments. remoteckan (Optional[ckanapi.RemoteCKAN]): CKAN instance. Defaults t...
Convert a dictionary into a string with assignments Each assignment is constructed based on: key assignment_operator value_representation(value) statement_separator, where key and value are the key and value of the dictionary. Moreover one can seprate the assignment statements by new lines. Parame...
Simple wrapper of json.load and json.loads. If json_input is None the output is an empty dictionary. If the input is a string that ends in .json it is decoded using json.load. Otherwise it is decoded using json.loads. Parameters ---------- json_input : str, None, optional input json ob...
Check if an object is jsonable. An object is jsonable if it is json serialisable and by loading its json representation the same object is recovered. Parameters ---------- obj : Python object Returns ------- bool >>> is_jsonable([1,2,3]) True >>> is_jsonable((1,2,3)) ...
Check if an expresion can be literal_eval. ---------- node_or_string : Input Returns ------- tuple (bool,python object) If it can be literal_eval the python object is returned. Otherwise None it is returned. >>> is_literal_eval('[1,2,3]') (True, ...
Return the duplicates in a list. The function relies on https://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-a-list . Parameters ---------- l : list Name Returns ------- set Duplicated values >>> find_duplicates([1,2,3]) set() >>> find_du...
Sort a dictionary by key or value. The function relies on https://docs.python.org/3/library/collections.html#collections.OrderedDict . The dulicated are determined based on https://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-a-list . Parameters ---------- d : dict ...
Group a dictionary by values. Parameters ---------- d : dict Input dictionary Returns ------- dict Output dictionary. The keys are the values of the initial dictionary and the values ae given by a list of keys corresponding to the value. >>> group_dict_by_value({2...
Find the possible parameters and "global" variables from a python code. This is achieved by parsing the abstract syntax tree. Parameters ---------- code : str Input code as string. exclude_variable : set, None, optional Variable to exclude. jsonable_parameter: bool, True, optio...
Increment the name where the incremental part is given by parameters. Parameters ---------- name : str, nbformat.notebooknode.NotebookNode Name start_marker : str The marker used before the incremental end_marker : str The marker after the incrementa Returns -------...
Reads the resource view given by identifier from HDX and returns ResourceView object Args: identifier (str): Identifier of resource view configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[ResourceView]: Re...
Read all resource views for a resource given by identifier from HDX and returns list of ResourceView objects Args: identifier (str): Identifier of resource configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: List[Re...
Check if resource view exists in HDX and if so, update resource view Returns: bool: True if updated and False if not def _update_resource_view(self, log=False): # type: () -> bool """Check if resource view exists in HDX and if so, update resource view Returns: ...
Check if resource view exists in HDX and if so, update it, otherwise create resource view Returns: None def create_in_hdx(self): # type: () -> None """Check if resource view exists in HDX and if so, update it, otherwise create resource view Returns: None ...
Copies all fields except id, resource_id and package_id from another resource view. Args: resource_view (Union[ResourceView,Dict,str]): Either a resource view id or resource view metadata either from a ResourceView object or a dictionary Returns: None def copy(self, resource_v...
Get tags cleanup dictionaries Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. url (Optional[str]): Url of tags cleanup spreadsheet. Defaults to None (internal configuration parameter). keycolumn (int): Column number of tag ...
Reads the user given by identifier from HDX and returns User object Args: identifier (str): Identifier of user configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[User]: User object if successful read, None...
Check if user exists in HDX and if so, update user Returns: None def update_in_hdx(self): # type: () -> None """Check if user exists in HDX and if so, update user Returns: None """ capacity = self.data.get('capacity') if capacity is not ...
Check if user exists in HDX and if so, update it, otherwise create user Returns: None def create_in_hdx(self): # type: () -> None """Check if user exists in HDX and if so, update it, otherwise create user Returns: None """ capacity = self.data.g...
Emails a user. Args: subject (str): Email subject text_body (str): Plain text email body html_body (str): HTML email body sender (Optional[str]): Email sender. Defaults to SMTP username. **kwargs: See below mail_options (List): Mail option...
Get all users in HDX Args: configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. **kwargs: See below q (str): Restrict to names containing a string. Defaults to all users. order_by (str): Field by which to sort - any user f...
Email a list of users Args: users (List[User]): List of users subject (str): Email subject text_body (str): Plain text email body html_body (str): HTML email body sender (Optional[str]): Email sender. Defaults to SMTP username. configurati...
Get organizations in HDX that this user is a member of. Args: permission (str): Permission to check for. Defaults to 'read'. Returns: List[Organization]: List of organizations in HDX that this user is a member of def get_organizations(self, permission='read'): # type: ...
Facade to simplify project setup that calls project main function Args: projectmainfn ((None) -> None): main function of project **kwargs: configuration parameters to pass to HDX Configuration class Returns: None def facade(projectmainfn, **kwargs): # (Callable[[None], None], Any)...
Tries loading the config from the given path. If no path is specified, the default config path is tried, and if that is not specified, we the default config is returned. def get_lint_config(config_path=None): """ Tries loading the config from the given path. If no path is specified, the default config path ...
Markdown lint tool, checks your markdown for styling issues def cli(list_files, config, ignore, path): """ Markdown lint tool, checks your markdown for styling issues """ files = MarkdownFileFinder.find_files(path) if list_files: echo_files(files) lint_config = get_lint_config(config) lint...
Main function def main(): """ Main function """ # Read configuration from the config file if present, else fall back to # command line options if args.config: config = config_file_parser.get_configuration(args.config) access_key_id = config['access-key-id'] secret_access_key = c...
Run the daemon :type check_interval: int :param check_interval: Delay in seconds between checks def run(self, check_interval=300): """ Run the daemon :type check_interval: int :param check_interval: Delay in seconds between checks """ while True: # ...
Iterates over the lines in a given markdown string and applies all the enabled line rules to each line def _apply_line_rules(self, markdown_string): """ Iterates over the lines in a given markdown string and applies all the enabled line rules to each line """ all_violations = [] lines = markdow...
Lints a list of files. :param files: list of files to lint :return: a list of violations found in the files def lint_files(self, files): """ Lints a list of files. :param files: list of files to lint :return: a list of violations found in the files """ all_violat...
Read values from a byte stream. Args: byte_stream (bytes): byte stream. Returns: tuple[object, ...]: values copies from the byte stream. Raises: IOError: if byte stream cannot be read. OSError: if byte stream cannot be read. def ReadFrom(self, byte_stream): """Read values fro...
Writes values to a byte stream. Args: values (tuple[object, ...]): values to copy to the byte stream. Returns: bytes: byte stream. Raises: IOError: if byte stream cannot be written. OSError: if byte stream cannot be read. def WriteTo(self, values): """Writes values to a byte ...
Ensure that we have snapshots for a given volume :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :returns: None def run(connection): """ Ensure that we have snapshots for a given volume :type connection: boto.ec2.connection.EC2Connection :param con...
Create a new snapshot :type volume: boto.ec2.volume.Volume :param volume: Volume to snapshot :returns: boto.ec2.snapshot.Snapshot -- The new snapshot def _create_snapshot(volume): """ Create a new snapshot :type volume: boto.ec2.volume.Volume :param volume: Volume to snapshot :returns: bo...
Ensure that a given volume has an appropriate snapshot :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type volume: boto.ec2.volume.Volume :param volume: Volume to check :returns: None def _ensure_snapshot(connection, volume): """ Ensure that a giv...
Remove old snapshots :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type volume: boto.ec2.volume.Volume :param volume: Volume to check :returns: None def _remove_old_snapshots(connection, volume): """ Remove old snapshots :type connection: bo...
List watched EBS volumes :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :returns: None def list(connection): """ List watched EBS volumes :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :returns: No...
Remove watching of a volume :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type volume_id: str :param volume_id: VolumeID to add to the watchlist :returns: bool - True if the watch was successful def unwatch(connection, volume_id): """ Remove watc...
Start watching a new volume :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type volume_id: str :param volume_id: VolumeID to add to the watchlist :type interval: str :param interval: Backup interval [hourly|daily|weekly|monthly|yearly] :type re...
Get Volume ID from the given volume. Input can be volume id or its Name tag. :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type volume: str :param volume: Volume ID or Volume Name :returns: Volume ID or None if the given volume does not exist def...
Start watching a new volume :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type file_name: str :param file_name: path to config file :returns: None def watch_from_file(connection, file_name): """ Start watching a new volume :type connection: ...
Start watching a new volume :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type file_name: str :param file_name: path to config file :returns: None def unwatch_from_file(connection, file_name): """ Start watching a new volume :type connection...
List all snapshots for the volume :type connection: boto.ec2.connection.EC2Connection :param connection: EC2 connection object :type volume: str :param volume: Volume ID or Volume Name :returns: None def list_snapshots(connection, volume): """ List all snapshots for the volume :type conne...
Get stems for the words using a given parser Example: from .parsing import ListParser parser = ListParser() stemmer = Morfologik() stemmer.stem(['ja tańczę a ona śpi], parser) [ ('ja': ['ja']), ('tańczę': ['tańczyć'...
Runs morfologik java jar and assumes that input and output is UTF-8 encoded. def _run_morfologik(self, words): """ Runs morfologik java jar and assumes that input and output is UTF-8 encoded. """ p = subprocess.Popen( ['java', '-jar', self.jar_path, 'plstem',...
Reads the showcase given by identifier from HDX and returns Showcase object Args: identifier (str): Identifier of showcase configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[Showcase]: Showcase object if s...
Get any datasets in the showcase Returns: List[Dataset]: List of datasets def get_datasets(self): # type: () -> List[hdx.data.dataset.Dataset] """Get any datasets in the showcase Returns: List[Dataset]: List of datasets """ assoc_result, dataset...
Get showcase dataset dict Args: showcase (Union[Showcase,Dict,str]): Either a showcase id or Showcase metadata from a Showcase object or dictionary Returns: Dict: showcase dataset dict def _get_showcase_dataset_dict(self, dataset): # type: (Union[hdx.data.dataset.Datas...
Add a dataset Args: dataset (Union[Dataset,Dict,str]): Either a dataset id or dataset metadata either from a Dataset object or a dictionary datasets_to_check (List[Dataset]): List of datasets against which to check existence of dataset. Defaults to datasets in showcase. Returns...
Add multiple datasets Args: datasets (List[Union[Dataset,Dict,str]]): A list of either dataset ids or dataset metadata from Dataset objects or dictionaries datasets_to_check (List[Dataset]): List of datasets against which to check existence of dataset. Defaults to datasets in showcase. ...
Find the possible parameters from a jupyter notebook (python3 only). The possible parameters are obtained by parsing the abstract syntax tree of the python code generated from the jupyter notebook. For a jupuyter notebook, a variable can be a possible parameter if: - it is defined in a cell that c...
Run an input jupyter notebook file and optionally (python3 only) parametrise it. One can pass arguments as keyword arguments or in a json format (file or string). For safety reasons, in order to avoid any code injection, only json serialisable keywords arguments are available. The keyword arguments...
Join values and convert to string Example: >>> from ww import l >>> lst = l('012') >>> lst.join(',') u'0,1,2' >>> lst.join(',', template="{}#") u'0#,1#,2#' >>> string = lst.join(',',\ formatte...
Append values at the end of the list Allow chaining. Args: values: values to be appened at the end. Example: >>> from ww import l >>> lst = l([]) >>> lst.append(1) [1] >>> lst [1] >>> lst.append(2...
Add all values of all iterables at the end of the list Args: iterables: iterable which content to add at the end Example: >>> from ww import l >>> lst = l([]) >>> lst.extend([1, 2]) [1, 2] >>> lst [1, 2] >...