diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-25 18:41:33 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-01-25 18:41:33 -0800 |
commit | f6f7450903bdbe36bd5fff146b942e34ad221557 (patch) | |
tree | c50332c832f414b5c0070e58a42ceb4751ed4d81 /python/fatcat_export.py | |
parent | 16256f8ed119c072c09b13b0b1a6d4a56bed5113 (diff) | |
download | fatcat-f6f7450903bdbe36bd5fff146b942e34ad221557.tar.gz fatcat-f6f7450903bdbe36bd5fff146b942e34ad221557.zip |
transform and import fixes/tweaks
Diffstat (limited to 'python/fatcat_export.py')
-rwxr-xr-x | python/fatcat_export.py | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/python/fatcat_export.py b/python/fatcat_export.py index cf8bf1c3..027d6c0a 100755 --- a/python/fatcat_export.py +++ b/python/fatcat_export.py @@ -12,9 +12,10 @@ import json import argparse import fatcat_client from fatcat_client.rest import ApiException -from fatcat_client import ReleaseEntity +from fatcat_client import ReleaseEntity, ContainerEntity, ChangelogEntry from fatcat_tools import uuid2fcid, entity_from_json, entity_to_dict, \ - release_to_elasticsearch, public_api + release_to_elasticsearch, container_to_elasticsearch, \ + changelog_to_elasticsearch, public_api def run_export_releases(args): @@ -30,9 +31,27 @@ def run_transform_releases(args): line = line.strip() if not line: continue - release = entity_from_json(line, ReleaseEntity) + entity = entity_from_json(line, ReleaseEntity) args.json_output.write( - json.dumps(release_to_elasticsearch(release)) + '\n') + json.dumps(release_to_elasticsearch(entity)) + '\n') + +def run_transform_containers(args): + for line in args.json_input: + line = line.strip() + if not line: + continue + entity = entity_from_json(line, ContainerEntity) + args.json_output.write( + json.dumps(container_to_elasticsearch(entity)) + '\n') + +def run_transform_changelogs(args): + for line in args.json_input: + line = line.strip() + if not line: + continue + entity = entity_from_json(line, ChangelogEntry) + args.json_output.write( + json.dumps(changelog_to_elasticsearch(entity)) + '\n') def run_export_changelog(args): api = args.api @@ -74,6 +93,24 @@ def main(): help="where to send output", default=sys.stdout, type=argparse.FileType('w')) + sub_transform_containers = subparsers.add_parser('transform-containers') + sub_transform_containers.set_defaults(func=run_transform_containers) + sub_transform_containers.add_argument('json_input', + help="JSON-per-line of container entities", + default=sys.stdin, type=argparse.FileType('r')) + sub_transform_containers.add_argument('json_output', + help="where to send output", + default=sys.stdout, type=argparse.FileType('w')) + + sub_transform_changelogs = subparsers.add_parser('transform-changelogs') + sub_transform_changelogs.set_defaults(func=run_transform_changelogs) + sub_transform_changelogs.add_argument('json_input', + help="JSON-per-line of changelog entries", + default=sys.stdin, type=argparse.FileType('r')) + sub_transform_changelogs.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', |