Skip to content

Commit

Permalink
Update HDX Python Country
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Jul 11, 2022
1 parent 0300613 commit 896c50b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ckanapi==4.7
defopt==6.3.0
email_validator==1.2.1
hdx-python-country==3.2.7
hdx-python-country==3.2.8
ndg-httpsclient==0.5.1
pyasn1==0.4.8
pyOpenSSL==22.0.0
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ install_requires =
ckanapi >= 4.7
defopt
email_validator
hdx-python-country>=3.2.7
hdx-python-country>=3.2.8
ndg-httpsclient
pyasn1
pyOpenSSL
Expand Down
34 changes: 19 additions & 15 deletions src/hdx/data/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@


class Resource(HDXObject):
"""Resource class containing all logic for creating, checking, and updating resources.
"""Resource class containing all logic for creating, checking, and updating
resources.
Args:
initial_data (Optional[Dict]): Initial resource metadata dictionary. Defaults to None.
Expand Down Expand Up @@ -106,10 +107,11 @@ def get_date_of_resource(
date_format: Optional[str] = None,
today: datetime.date = datetime.date.today(),
) -> Dict:
"""Get resource date as datetimes and strings in specified format. If no format is supplied, the ISO 8601
format is used. Returns a dictionary containing keys startdate (start date as datetime), enddate (end
date as datetime), startdate_str (start date as string), enddate_str (end date as string) and ongoing
(whether the end date is a rolls forward every day).
"""Get resource date as datetimes and strings in specified format. If no format
is supplied, the ISO 8601 format is used. Returns a dictionary containing keys
startdate (start date as datetime), enddate (end date as datetime),
startdate_str (start date as string), enddate_str (end date as string) and
ongoing (whether the end date is a rolls forward every day).
Args:
date_format (Optional[str]): Date format. None is taken to be ISO 8601. Defaults to None.
Expand Down Expand Up @@ -201,10 +203,10 @@ def get_mapped_format(
Returns:
Optional[str]: Mapped format or None if no mapping found
"""
if configuration is None:
configuration = Configuration.read()
if not file_type:
return None
if configuration is None:
configuration = Configuration.read()
file_type = file_type.lower()
mappings = cls.read_formats_mappings(configuration=configuration)
format = mappings.get(file_type)
Expand Down Expand Up @@ -232,7 +234,6 @@ def set_file_type(self, file_type: str) -> str:
Args:
file_type (str): File type to set on resource
log_none (bool): Whether to log an informational message about the file type being None. Defaults to True.
Returns:
str: Format that was set
Expand All @@ -248,7 +249,8 @@ def set_file_type(self, file_type: str) -> str:
return format

def clean_file_type(self) -> str:
"""Clean the resource's file type, setting it to None if it is invalid and cannot be mapped
"""Clean the resource's file type, setting it to None if it is invalid and
cannot be mapped
Returns:
str: Format that was set
Expand All @@ -270,7 +272,7 @@ def set_file_to_upload(
Args:
file_to_upload (str): Local path to file to upload
guess_format_from_suffix (bool): Whether to try to set format based on file suffix. Defaults to False.
guess_format_from_suffix (bool): Set format from file suffix. Defaults to False.
Returns:
Optional[str]: The format that was guessed or None if no format was set
Expand All @@ -284,8 +286,8 @@ def set_file_to_upload(
return format

def check_url_filetoupload(self) -> None:
"""Check if url or file to upload provided for resource and add resource_type and url_type if not supplied.
Correct the file type.
"""Check if url or file to upload provided for resource and add resource_type
and url_type if not supplied. Correct the file type.
Returns:
None
Expand Down Expand Up @@ -318,8 +320,9 @@ def check_url_filetoupload(self) -> None:
self.clean_file_type()

def check_required_fields(self, ignore_fields: List[str] = list()) -> None:
"""Check that metadata for resource is complete. The parameter ignore_fields should be set if required to
any fields that should be ignored for the particular operation.
"""Check that metadata for resource is complete. The parameter ignore_fields
should be set if required to any fields that should be ignored for the
particular operation.
Args:
ignore_fields (List[str]): Fields to ignore. Default is [].
Expand Down Expand Up @@ -431,7 +434,8 @@ def search_in_hdx(
return resources

def download(self, folder: Optional[str] = None) -> Tuple[str, str]:
"""Download resource store to provided folder or temporary folder if no folder supplied
"""Download resource store to provided folder or temporary folder if no folder
supplied
Args:
folder (Optional[str]): Folder to download resource to. Defaults to None.
Expand Down

0 comments on commit 896c50b

Please sign in to comment.