view globalneighbors/main.py @ 25:991bce6b6881 default tip

[knn] placeholder for planning session
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Sep 2017 14:35:50 -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()