aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-10-08 15:57:35 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-10-08 15:57:35 -0700
commit4b7c3c7b317cf4793f5ba5ad0d96102f103b66a3 (patch)
treee0dd776315e4b86ed544d8847fddea3456568224
parent76db7f4048116a23c82bdd70bb11dd004e347e8e (diff)
downloadfatcat-4b7c3c7b317cf4793f5ba5ad0d96102f103b66a3.tar.gz
fatcat-4b7c3c7b317cf4793f5ba5ad0d96102f103b66a3.zip
dict wrapper for entity_from_json()
-rw-r--r--python/fatcat_tools/transforms/__init__.py2
-rw-r--r--python/fatcat_tools/transforms/entities.py8
2 files changed, 7 insertions, 3 deletions
diff --git a/python/fatcat_tools/transforms/__init__.py b/python/fatcat_tools/transforms/__init__.py
index 863472c0..735d1b29 100644
--- a/python/fatcat_tools/transforms/__init__.py
+++ b/python/fatcat_tools/transforms/__init__.py
@@ -1,4 +1,4 @@
-from .entities import entity_to_dict, entity_from_json
+from .entities import entity_to_dict, entity_from_json, entity_from_dict
from .elasticsearch import release_to_elasticsearch, container_to_elasticsearch, changelog_to_elasticsearch
from .csl import release_to_csl, citeproc_csl
diff --git a/python/fatcat_tools/transforms/entities.py b/python/fatcat_tools/transforms/entities.py
index 8e5de286..ae666413 100644
--- a/python/fatcat_tools/transforms/entities.py
+++ b/python/fatcat_tools/transforms/entities.py
@@ -1,5 +1,5 @@
-
+import json
import collections
from fatcat_openapi_client import ApiClient
@@ -21,7 +21,7 @@ def entity_from_json(json_str, entity_type, api_client=None):
"""
Hack to take advantage of the code-generated deserialization code
- See not on `entity_to_dict()` about api_client argument.
+ See note on `entity_to_dict()` about api_client argument.
"""
if not api_client:
api_client = ApiClient()
@@ -29,3 +29,7 @@ def entity_from_json(json_str, entity_type, api_client=None):
thing.data = json_str
return api_client.deserialize(thing, entity_type)
+def entity_from_dict(obj, entity_type, api_client=None):
+ json_str = json.dumps(obj)
+ return entity_from_json(json_str, entity_type, api_client=api_client)
+