Created
December 21, 2016 16:41
-
-
Save vperron/628000717d8282c367a343bf27215fda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# Keeps ordering | |
import ruamel.yaml | |
with open(sys.argv[1], 'r') as f: | |
data = ruamel.yaml.load(f.read(), ruamel.yaml.RoundTripLoader) | |
lst = [] | |
for svc in data['services']: | |
if 'endpoints' in svc: | |
for k, v in dict(svc['endpoints']).items(): | |
if 'url' in v: | |
v.pop('url') | |
if not svc['endpoints'][k]: | |
svc['endpoints'].pop(k) | |
if not svc['endpoints']: | |
svc.pop('endpoints') | |
lst.append(svc) | |
print(ruamel.yaml.dump(lst, Dumper=ruamel.yaml.RoundTripDumper), end='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import yaml | |
with open(sys.argv[1], 'r') as f: | |
data = yaml.safe_load(f.read()) | |
lst = [] | |
for svc in data['services_urls']: | |
endpoints = svc.get('endpoints', None) | |
if not endpoints: | |
continue | |
lst.append({ | |
'hrid': svc['hrid'], | |
'urls': {k: v['url'] for k, v in endpoints.items()} | |
}) | |
print(yaml.safe_dump(lst, default_flow_style=False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment