#!/usr/bin/env python3

'''

DEPS:
* Make sure to install PyYAML probably with pip3.https://pyyaml.org/wiki/PyYAMLDocumentation

NOTE:
* for each arg of type URL http request get a application/json
* convert the json to yaml and print out

'''

import sys
import urllib
from urllib.request import urlopen
import json
import yaml

def main(argv):
    for val in argv:
        try:
            req = urllib.request.Request(val)
            response = urllib.request.urlopen(req).read()
            result = json.loads(response.decode('utf-8'))
            print(yaml.dump(result, default_flow_style=False))
        except urllib.error.URLError as e:
            print(e.reason)
        except TypeError as e:
            print(e)
        except ValueError as e:
            print(e)

if __name__ == "__main__":
   main(sys.argv[1:])
