view globalneighbors/main.py @ 4:8e130b7bfed9

remove unintended boilerplate
author Jeff Hammel <k0scist@gmail.com>
date Sat, 24 Jun 2017 14:48:55 -0700
parents 5dba84370182
children
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
locate nearest cities
"""

# imports
import argparse
import json
import os
import sys
import time
from .cli import CitiesParser
from .locations import locations
from .read import read_cities
from .schema import fields

try:
    # python 2
    string = (str, unicode)
except NameError:
    # python 3
    string = (str, )


def main(args=sys.argv[1:]):
    """CLI"""

    # parse command line options
    parser = CitiesParser(description=__doc__)
    options = parser.parse_args(args)

    # read data
    cities = list(read_cities(options.cities, fields=fields))

    # get locations
    city_locations = locations(cities)

    # output
    print (json.dumps(city_locations, indent=2, sort_keys=True))


if __name__ == '__main__':
    main()