Mercurial > hg > GlobalNeighbors
diff globalneighbors/main.py @ 0:5dba84370182
initial commit; half-working prototype
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 12:03:39 -0700 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/globalneighbors/main.py Sat Jun 24 12:03:39 2017 -0700 @@ -0,0 +1,47 @@ +#!/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() + +