ckanapi-harvesters 0.0.4__py3-none-any.whl → 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ckanapi_harvesters/builder/example/builder_example_test_sql.py +21 -0
- ckanapi_harvesters/ckan_api/ckan_api_2_readonly.py +22 -17
- {ckanapi_harvesters-0.0.4.dist-info → ckanapi_harvesters-0.0.6.dist-info}/METADATA +1 -1
- {ckanapi_harvesters-0.0.4.dist-info → ckanapi_harvesters-0.0.6.dist-info}/RECORD +6 -6
- {ckanapi_harvesters-0.0.4.dist-info → ckanapi_harvesters-0.0.6.dist-info}/WHEEL +0 -0
- {ckanapi_harvesters-0.0.4.dist-info → ckanapi_harvesters-0.0.6.dist-info}/top_level.txt +0 -0
|
@@ -37,12 +37,33 @@ def run(ckan:CkanApi = None):
|
|
|
37
37
|
ckan.api_help_show("datastore_search_sql")
|
|
38
38
|
except CkanNotFoundError:
|
|
39
39
|
print("No datastore_search_sql help")
|
|
40
|
+
|
|
40
41
|
users_table_id = mdl.get_or_query_resource_id(ckan, "users.csv")
|
|
42
|
+
traces_table_id = mdl.get_or_query_resource_id(ckan, "traces.csv")
|
|
43
|
+
|
|
44
|
+
# datastore_search simple API
|
|
45
|
+
cursor = ckan.datastore_search_cursor(users_table_id, limit=1)
|
|
46
|
+
document = next(cursor)
|
|
47
|
+
user_id = document["user_id"]
|
|
48
|
+
cursor = ckan.datastore_search_cursor(traces_table_id, filters={"user_id": int(user_id)}, limit=10)
|
|
49
|
+
for document in cursor:
|
|
50
|
+
print(document)
|
|
51
|
+
|
|
41
52
|
try:
|
|
42
53
|
ckan.datastore_search_sql(f'SELECT * FROM "{users_table_id}"')
|
|
43
54
|
except CkanSqlCapabilityError:
|
|
44
55
|
print("datastore_search_sql is not accessible")
|
|
45
56
|
|
|
57
|
+
query = f"""
|
|
58
|
+
SELECT t.*, u.* FROM "{traces_table_id}" t
|
|
59
|
+
JOIN "{users_table_id}" u ON t.user_id = u.user_id
|
|
60
|
+
WHERE t.user_id = {user_id}
|
|
61
|
+
LIMIT 10
|
|
62
|
+
"""
|
|
63
|
+
cursor = ckan.datastore_search_sql_cursor(query, return_df=False)
|
|
64
|
+
for document in cursor:
|
|
65
|
+
print(document)
|
|
66
|
+
|
|
46
67
|
print("Tests done.")
|
|
47
68
|
|
|
48
69
|
|
|
@@ -280,7 +280,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
280
280
|
### Search method ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
281
281
|
def _api_datastore_search_raw(self, resource_id:str, *, filters:dict=None, q:str=None, fields:List[str]=None,
|
|
282
282
|
distinct:bool=None, sort:str=None, limit:int=None, offset:int=0, format:str=None,
|
|
283
|
-
params:dict=None, compute_len:
|
|
283
|
+
params:dict=None, compute_len:bool=False) -> CkanActionResponse:
|
|
284
284
|
"""
|
|
285
285
|
API call to datastore_search. Performs queries on the DataStore.
|
|
286
286
|
|
|
@@ -338,7 +338,8 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
338
338
|
raise response.default_error(self)
|
|
339
339
|
|
|
340
340
|
def _api_datastore_search_df(self, resource_id:str, *, filters:dict=None, q:str=None, fields:List[str]=None,
|
|
341
|
-
distinct:bool=None, sort:str=None, limit:int=None, offset:int=0, format:str=None,
|
|
341
|
+
distinct:bool=None, sort:str=None, limit:int=None, offset:int=0, format:str=None,
|
|
342
|
+
params:dict=None, compute_len:bool=True) -> pd.DataFrame:
|
|
342
343
|
"""
|
|
343
344
|
Convert output of _api_datastore_search_raw to pandas DataFrame.
|
|
344
345
|
"""
|
|
@@ -377,7 +378,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
377
378
|
def _api_datastore_search_all(self, resource_id:str, *, filters:dict=None, q:str=None, fields:List[str]=None,
|
|
378
379
|
distinct:bool=None, sort:str=None, limit:int=None, offset:int=0, format:str=None,
|
|
379
380
|
search_all:bool=True, params:dict=None, return_df:bool=True, compute_len:bool=False) \
|
|
380
|
-
-> Union[pd.DataFrame,
|
|
381
|
+
-> Union[pd.DataFrame, ListRecords, Any]:
|
|
381
382
|
"""
|
|
382
383
|
Successive calls to _api_datastore_search_df until an empty list is received.
|
|
383
384
|
|
|
@@ -409,7 +410,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
409
410
|
search_all=search_all, resource_id=resource_id, filters=filters, q=q, fields=fields, distinct=distinct, sort=sort, format=format, compute_len=compute_len)
|
|
410
411
|
# aggregate results, depending on the format
|
|
411
412
|
if self.params.dry_run:
|
|
412
|
-
return []
|
|
413
|
+
return []
|
|
413
414
|
if format is not None:
|
|
414
415
|
format = format.lower()
|
|
415
416
|
if len(responses) > 0:
|
|
@@ -420,12 +421,12 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
420
421
|
fields_type_dict = None
|
|
421
422
|
df_args = {}
|
|
422
423
|
if format is None or format == "objects":
|
|
423
|
-
return ListRecords(sum([response.result["records"] for response in responses], []))
|
|
424
|
+
return ListRecords(sum([response.result["records"] for response in responses], []))
|
|
424
425
|
else:
|
|
425
426
|
if format == "lists":
|
|
426
|
-
return sum([response.result["records"] for response in responses], [])
|
|
427
|
+
return sum([response.result["records"] for response in responses], [])
|
|
427
428
|
else:
|
|
428
|
-
return "\n".join([response.result["records"] for response in responses])
|
|
429
|
+
return "\n".join([response.result["records"] for response in responses])
|
|
429
430
|
|
|
430
431
|
def _api_datastore_search_all_generator(self, resource_id:str, *, filters:dict=None, q:str=None, fields:List[str]=None,
|
|
431
432
|
distinct:bool=None, sort:str=None, limit:int=None, offset:int=0,
|
|
@@ -486,6 +487,10 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
486
487
|
params["limit"] = limit
|
|
487
488
|
response = self._api_action_request(f"datastore_search_sql", method=RequestType.Post, params=params)
|
|
488
489
|
if response.success:
|
|
490
|
+
if response.dry_run:
|
|
491
|
+
return response
|
|
492
|
+
else:
|
|
493
|
+
response.len = len(response.result["records"])
|
|
489
494
|
return response
|
|
490
495
|
elif response.status_code == 400 and response.success_json_loads and response.response.text == '"Bad request - Action name not known: datastore_search_sql"':
|
|
491
496
|
raise CkanSqlCapabilityError(self, response)
|
|
@@ -513,7 +518,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
513
518
|
|
|
514
519
|
def _api_datastore_search_sql_all(self, sql:str, *, params:dict=None,
|
|
515
520
|
search_all:bool=True, limit:int=None, offset:int=0, return_df:bool=True) \
|
|
516
|
-
-> Union[pd.DataFrame,
|
|
521
|
+
-> Union[pd.DataFrame, ListRecords]:
|
|
517
522
|
"""
|
|
518
523
|
Successive calls to _api_datastore_search_sql until an empty list is received.
|
|
519
524
|
|
|
@@ -543,7 +548,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
543
548
|
fields_type_dict = CkanApiReadOnly.read_fields_type_dict(response.result["fields"])
|
|
544
549
|
else:
|
|
545
550
|
fields_type_dict = None
|
|
546
|
-
return ListRecords(sum([response.result["records"] for response in responses], []))
|
|
551
|
+
return ListRecords(sum([response.result["records"] for response in responses], []))
|
|
547
552
|
|
|
548
553
|
def _api_datastore_search_sql_all_generator(self, sql:str, *, params:dict=None,
|
|
549
554
|
search_all:bool=True, limit:int=None, offset:int=0, return_df:bool=True) \
|
|
@@ -659,8 +664,8 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
659
664
|
|
|
660
665
|
def datastore_search_cursor(self, resource_id:str, *, filters:dict=None, q:str=None, fields:List[str]=None,
|
|
661
666
|
distinct:bool=None, sort:str=None, limit:int=None, offset:int=0, params:dict=None,
|
|
662
|
-
search_all:bool=False, search_method:bool=True, format:str=None, return_df:bool=
|
|
663
|
-
-> Generator[Union[pd.Series,
|
|
667
|
+
search_all:bool=False, search_method:bool=True, format:str=None, return_df:bool=False) \
|
|
668
|
+
-> Generator[Union[pd.Series, dict, list, str], Any, None]:
|
|
664
669
|
"""
|
|
665
670
|
Cursor on rows
|
|
666
671
|
"""
|
|
@@ -682,12 +687,12 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
682
687
|
for response in generator:
|
|
683
688
|
fields_type_dict = CkanApiReadOnly.read_fields_type_dict(response.result["fields"])
|
|
684
689
|
for element in response.result["records"]:
|
|
685
|
-
yield element
|
|
690
|
+
yield element
|
|
686
691
|
else:
|
|
687
692
|
for response in generator:
|
|
688
693
|
fields_type_dict = CkanApiReadOnly.read_fields_type_dict(response.result["fields"])
|
|
689
694
|
for element in response.result["records"]:
|
|
690
|
-
yield element
|
|
695
|
+
yield element
|
|
691
696
|
else:
|
|
692
697
|
raise TypeError("dumping datastore without parsing with a DataFrame does not return an iterable object")
|
|
693
698
|
|
|
@@ -752,8 +757,8 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
752
757
|
return self._api_datastore_search_sql_all_generator(sql, params=params, limit=limit, offset=offset, search_all=search_all, return_df=return_df)
|
|
753
758
|
|
|
754
759
|
def datastore_search_sql_cursor(self, sql:str, *, params:dict=None, search_all:bool=False,
|
|
755
|
-
limit:int=None, offset:int=0, return_df:bool=
|
|
756
|
-
-> Generator[Union[pd.Series,
|
|
760
|
+
limit:int=None, offset:int=0, return_df:bool=False) \
|
|
761
|
+
-> Generator[Union[pd.Series,dict], Any, None]:
|
|
757
762
|
generator = self.datastore_search_sql_generator(sql, params=params, search_all=search_all,
|
|
758
763
|
limit=limit, offset=offset, return_df=return_df)
|
|
759
764
|
if return_df:
|
|
@@ -769,7 +774,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
769
774
|
for response in generator:
|
|
770
775
|
fields_type_dict = CkanApiReadOnly.read_fields_type_dict(response.result["fields"])
|
|
771
776
|
for element in response.result["records"]:
|
|
772
|
-
yield element
|
|
777
|
+
yield element
|
|
773
778
|
|
|
774
779
|
def datastore_search_sql_find_one(self, sql:str, *, params:dict=None,
|
|
775
780
|
offset:int=0, return_df:bool=True) -> Union[pd.DataFrame, Tuple[ListRecords, dict]]:
|
|
@@ -912,7 +917,7 @@ class CkanApiReadOnly(CkanApiMap):
|
|
|
912
917
|
## Mapping of resource aliases from table
|
|
913
918
|
def list_datastore_aliases(self) -> List[CkanAliasInfo]:
|
|
914
919
|
alias_resource_id = "_table_metadata" # resource name of table containing CKAN aliases
|
|
915
|
-
alias_list_dict
|
|
920
|
+
alias_list_dict = self.datastore_search(alias_resource_id, search_all=True, return_df=False, format="objects", search_method=True)
|
|
916
921
|
alias_list = [CkanAliasInfo(alias_dict) for alias_dict in alias_list_dict]
|
|
917
922
|
for alias_info in alias_list:
|
|
918
923
|
if alias_info.alias_of is not None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ckanapi_harvesters
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
4
4
|
Summary: Package helping to upload local resources to a CKAN server using the CKAN API. Metadata and the list of resources can be defined in an Excel spreadsheet. The package includes requests to download resources and checks metadata against formatting rules.
|
|
5
5
|
Author-email: ifpen-gp <63413841+ifpen-gp@users.noreply.github.com>
|
|
6
6
|
Maintainer-email: ifpen-gp <63413841+ifpen-gp@users.noreply.github.com>
|
|
@@ -48,7 +48,7 @@ ckanapi_harvesters/builder/example/builder_example_download.py,sha256=teL6iusYbT
|
|
|
48
48
|
ckanapi_harvesters/builder/example/builder_example_generate_data.py,sha256=dspJAdb0biAz_v159nWcDrVaG7uXs1DoXg6EmGQFmt4,3527
|
|
49
49
|
ckanapi_harvesters/builder/example/builder_example_patch_upload.py,sha256=10iaJ78IBJTd-Uti-Q9TLFfz9tQw13UKwvSg9i5NrlM,1634
|
|
50
50
|
ckanapi_harvesters/builder/example/builder_example_policy.py,sha256=-jy89E_z2Mp5SrsS7zd0Y4ubrQn67NHcVxWh6mDyUFQ,4593
|
|
51
|
-
ckanapi_harvesters/builder/example/builder_example_test_sql.py,sha256=
|
|
51
|
+
ckanapi_harvesters/builder/example/builder_example_test_sql.py,sha256=aaZhIi3jRwzDgvSrPuKOYz1_wBZVNcq-JGtBNXeVEcY,2283
|
|
52
52
|
ckanapi_harvesters/builder/example/builder_example_tests.py,sha256=1JxpKoYnRm35J9QW7asS5jSygUYEMv0C6s_wufm2pSg,2934
|
|
53
53
|
ckanapi_harvesters/builder/example/builder_example_tests_offline.py,sha256=VcFxsnUjtkAFwdmSQaphaEPjMgzo6XR3Dubvxece_Yk,1773
|
|
54
54
|
ckanapi_harvesters/builder/example/package/ckan-dpg.svg,sha256=YNk-H1EEu-ipdLt5Ik0nUmtXBqUSU_XoamAkFdOT65A,9683
|
|
@@ -65,7 +65,7 @@ ckanapi_harvesters/ckan_api/__init__.py,sha256=ZEe0P35WNVxhQPUCnaLRIfMBzbL44oOHy
|
|
|
65
65
|
ckanapi_harvesters/ckan_api/ckan_api.py,sha256=_XmiDL89veF4LODisq1FwWOAkJuWpzynbIAUxKsv_ds,439
|
|
66
66
|
ckanapi_harvesters/ckan_api/ckan_api_0_base.py,sha256=WjICbv1N1N-rIkwmh3D2U6GB5jG0HzNCN-_bhihFrJw,43253
|
|
67
67
|
ckanapi_harvesters/ckan_api/ckan_api_1_map.py,sha256=4N9BE9dlImIdO_XOut7M5nwhe9IY-lvAjtXB9BDgJzs,52537
|
|
68
|
-
ckanapi_harvesters/ckan_api/ckan_api_2_readonly.py,sha256=
|
|
68
|
+
ckanapi_harvesters/ckan_api/ckan_api_2_readonly.py,sha256=tOVc-kpItiy9v_oCrWyK8BGscmKjuKKS1tNbBU9yIcA,54794
|
|
69
69
|
ckanapi_harvesters/ckan_api/ckan_api_3_policy.py,sha256=zzm7CxYrwlrRWtQq62qJCzoHKM068Z5Fk65eMpv86Ik,11595
|
|
70
70
|
ckanapi_harvesters/ckan_api/ckan_api_4_readwrite.py,sha256=L2WEHJiVq9J_uXgNDr3YDGi8l6HuMmabQAkpSXE2eZ4,30816
|
|
71
71
|
ckanapi_harvesters/ckan_api/ckan_api_5_manage.py,sha256=KFfMjXmqLJZq0btyJVcfTPzKcFb_4psuQpMFVO9vDYI,65578
|
|
@@ -105,7 +105,7 @@ ckanapi_harvesters/policies/data_format_policy_lists.py,sha256=Lh_pYUvolW6QujaHd
|
|
|
105
105
|
ckanapi_harvesters/policies/data_format_policy_tag_groups.py,sha256=KBxXm9hLgaiuJDTnP-ti2iZAyvf04uvUkIoo_Jqbpog,1341
|
|
106
106
|
ckanapi_harvesters/reports/__init__.py,sha256=LuacieaFOyqaivLuaRAD7Umx0rE_Lz9jD7bL88XLonw,137
|
|
107
107
|
ckanapi_harvesters/reports/admin_report.py,sha256=fSqNSLGe-XFmRQ6QanOm9VcAIbjDsiCNQSpVIGsH9XE,16773
|
|
108
|
-
ckanapi_harvesters-0.0.
|
|
109
|
-
ckanapi_harvesters-0.0.
|
|
110
|
-
ckanapi_harvesters-0.0.
|
|
111
|
-
ckanapi_harvesters-0.0.
|
|
108
|
+
ckanapi_harvesters-0.0.6.dist-info/METADATA,sha256=C-ko9EEupf9Ry8vZrdfk0y82peVZyHS77fPRL51UZAI,12564
|
|
109
|
+
ckanapi_harvesters-0.0.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
110
|
+
ckanapi_harvesters-0.0.6.dist-info/top_level.txt,sha256=WvJprCJXBEK-Eew36dTdVdt9I_r4AdgA2Kur3RhLTPg,19
|
|
111
|
+
ckanapi_harvesters-0.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|