@@ -67,9 +67,9 @@ def follow_url(
6767 # Is it a CKAN resource? (Assumes the v.3 API for now)
6868 result = CKAN_URL .match (url )
6969 if result :
70- urls = _get_ckan_urls (result .group (2 ), result .group (3 ))
71- if urls :
72- return urls [ 0 ]
70+ result = _get_ckan_urls (result .group (2 ), result .group (3 ))
71+ if result :
72+ return result
7373
7474 # Is it a Google Drive "open" URL?
7575 result = GOOGLE_DRIVE_URL .match (url )
@@ -106,7 +106,7 @@ def follow_url(
106106 return url
107107
108108
109- def _get_ckan_urls (dataset_id : str , resource_id : str ) -> list [ str ] :
109+ def _get_ckan_urls (dataset_id : str , resource_id : str ) -> str | None :
110110 """Look up a CKAN download URL starting from a dataset or resource page
111111
112112 If the link is to a dataset page, try the first resource. If it's
@@ -120,16 +120,16 @@ def _get_ckan_urls(dataset_id: str, resource_id: str) -> list[str]:
120120
121121 Returns:
122122 The direct-download URL for the CKAN dataset
123-
124123 """
125- result_urls = []
126124 if resource_id :
127125 resource = hdx .data .resource .Resource .read_from_hdx (resource_id )
128126 if resource :
129- result_urls .append (resource ["url" ])
130- else :
131- dataset = hdx .data .dataset .Dataset .read_from_hdx (dataset_id )
132- for resource in dataset .get_resources ():
133- if url := resource .get ("url" ):
134- result_urls .append (url )
135- return result_urls
127+ return resource ["url" ]
128+
129+ dataset = hdx .data .dataset .Dataset .read_from_hdx (dataset_id )
130+ if not dataset :
131+ return None
132+ for resource in dataset .get_resources ():
133+ if url := resource .get ("url" ):
134+ return url
135+ return None
0 commit comments