Skip to content

Instantly share code, notes, and snippets.

@vperron
Created December 21, 2016 16:41
Show Gist options
  • Save vperron/628000717d8282c367a343bf27215fda to your computer and use it in GitHub Desktop.
Save vperron/628000717d8282c367a343bf27215fda to your computer and use it in GitHub Desktop.
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='')
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