limestone

A KDE marble commandline interface.
git clone git://r-36.net/limestone
Log | Files | Refs | LICENSE

commit 014c3a1d018528adfcaedf464dfc15a5a4248431
parent 02ed0547552e86a34ccfc1ea870ee6f17b8c6a26
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri,  4 Dec 2015 16:25:18 +0100

Add geo(1) and geopos(1) utilities.

geo(1) is a wrapper around limestone and geopos to search for some location and
display it in limestone.

geopos(1) is a Python script to search for positions of locations, addresses
or IPs.

Diffstat:
utils/geo | 11+++++++++++
utils/geopos | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/utils/geo b/utils/geo @@ -0,0 +1,11 @@ +#!/bin/sh +# +# Copy me if you can. +# by 20h +# +# +# usage: geo position description +# + +limestone -z 3000 $(geopos -g "$@") + diff --git a/utils/geopos b/utils/geopos @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# coding=utf-8 +# +# Copy me if you can. +# by 20h +# +# usage: geopos [-gjri] position description +# -g - produce geo: URI +# -j - print JSON output +# -i - get position of some IP +# -r - do reverse search of a position to some description +# + +import sys +import os +import geocoder +import getopt + +def usage(app): + app = os.path.basename(app) + sys.stderr.write("usage: %s [-gjri] loc\n" % (app)) + sys.exit(1) + +def main(args): + try: + opts, largs = getopt.getopt(args[1:], "hgjri") + except getopt.GetoptError as err: + print(str(err)) + usage(args[0]) + + printjson = False + isreverse = False + isip = False + dogeouri = False + for o, a in opts: + if o == "-h": + usage(args[0]) + elif o == "-g": + dogeouri = True + elif o == "-j": + printjson = True + elif o == "-i": + isip = True + elif o == "-r": + isreverse = True + else: + assert False, "unhandled option" + + if len(largs) < 1: + usage(args[0]) + + g = None + sarg = " ".join(largs) + if isreverse == True: + g = geocoder.reverse(sarg) + elif isip == True: + g = geocoder.ip(sarg) + else: + g = geocoder.google(sarg) + + retval = 1 + if printjson == True: + if "ERROR" not in b.status: + print(g.json) + else: + if dogeouri == True: + if "lat" in g.json and "lng" in g.json: + print("geo:%s,%s" % (g.json["lat"], g.json["lng"])) + retval = 0 + else: + for k in ("lat", "lng", "address"): + if k in g.json: + if type(g.json[k]) == bytes: + s = g.json[k].decode("utf-8") + else: + s = g.json[k] + print("%s: %s" % (k, s)) + retval = 0 + + return retval + +if __name__ == "__main__": + sys.exit(main(sys.argv)) +