summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-24 16:15:54 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-24 16:15:54 -0800
commit6d00f774eaee1fab1a3af7e61a4f20273490f52d (patch)
treee49d50a75e939a5c59d468682d8d7f7665621bf2
parent457c1612e29730e5b9ee2820c3ea813a1d2dd405 (diff)
downloadfatcat-6d00f774eaee1fab1a3af7e61a4f20273490f52d.tar.gz
fatcat-6d00f774eaee1fab1a3af7e61a4f20273490f52d.zip
implement transform-releases in export script
-rwxr-xr-xpython/fatcat_export.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/python/fatcat_export.py b/python/fatcat_export.py
index 60c1caf1..6a5395de 100755
--- a/python/fatcat_export.py
+++ b/python/fatcat_export.py
@@ -12,7 +12,8 @@ import json
import argparse
import fatcat_client
from fatcat_client.rest import ApiException
-from fatcat_tools import uuid2fcid
+from fatcat_client import ReleaseEntity
+from fatcat_tools import uuid2fcid, entity_from_json, release_to_elasticsearch
def run_export_releases(args):
conf = fatcat_client.Configuration()
@@ -24,6 +25,15 @@ def run_export_releases(args):
release = api.get_release(id=ident, expand="all")
args.json_output.write(json.dumps(release.to_dict()) + "\n")
+def run_transform_releases(args):
+ for line in args.json_input:
+ line = line.strip()
+ if not line:
+ continue
+ release = entity_from_json(line, ReleaseEntity)
+ args.json_output.write(
+ json.dumps(release_to_elasticsearch(release)) + '\n')
+
def run_export_changelog(args):
conf = fatcat_client.Configuration()
conf.host = args.host_url
@@ -57,6 +67,15 @@ def main():
help="where to send output",
default=sys.stdout, type=argparse.FileType('w'))
+ sub_transform_releases = subparsers.add_parser('transform-releases')
+ sub_transform_releases.set_defaults(func=run_transform_releases)
+ sub_transform_releases.add_argument('json_input',
+ help="JSON-per-line of release entities",
+ default=sys.stdin, type=argparse.FileType('r'))
+ sub_transform_releases.add_argument('json_output',
+ help="where to send output",
+ default=sys.stdout, type=argparse.FileType('w'))
+
sub_changelog = subparsers.add_parser('changelog')
sub_changelog.set_defaults(func=run_export_changelog)
sub_changelog.add_argument('--start',