#!/usr/bin/python
#  -*- coding: utf-8 -*-
# ~/bin/lat-long-nr-2-olc.py (executable!) # chmod +x ~/bin/lat-long-nr-2-olc.py
# ------------------------------------------------------------------------------
# Marc Meurrens June 2019
# Convert (Latitude, Lontitude, Number of digits) to Open Location Code format
# ------------------------------------------------------------------------------
# see also : < olc-2-lat-long.py > and < olc.py > and < lat-long-2-olc.py > (by Daniel Debaste)
# all these scripts are located in ~/bin
# ------------------------------------------------------------------------------
# USAGE
# usage in a terminal :
# $ lat-long-nr-2-olc.py 36.70924 -4.44472 10 
#
# usage in a batch script :
# code=$( lat-long-nr-2-olc.py $latitude $longitude $nrOfDigits ) 
# echo $code
#
# usage in our script : lat-long-nr-2-olc.py.sh
## $1 = latitude = float(sys.argv[1]) # e.g. 50.8351 (Brussels) # 36.70924 (Málaga)
## $2 = longitude = float(sys.argv[2]) # e.g. 4.30969 (Brussels) # -4.44472 (Málaga) 
## $3 precision = int(sys.argv[3]) # e.g. 8 or 10 # range = [8 - 11] (or up to 15 !) 
## e.g. 9F26R8P5+2VW (Brussels) # 8C9QPH54+M4R (Málaga)
# lat-long-nr-2-olc.py $1 $2 $3
# ------------------------------------------------------------------------------
 
import sys
latitude = float(sys.argv[1]) # e.g. 50.8351 (Brussels) # 36.70924 (Málaga)
longitude = float(sys.argv[2]) # e.g. 4.30969 (Brussels) # -4.44472 (Málaga) 
precision = int(sys.argv[3]) # e.g. 8 or 10 # range = [8 - 15] 
# e.g. 9F26R8P5+2VW (Brussels) # 8C9QPH54+M4R (Málaga)

# print latitude
# print longitude
# print precision

# sys.path.append('/.geoloc/scripts/python') # obsolete : everything is now in ~/bin
import olc
openlocationcode = olc.encode(latitude, longitude, precision)

print openlocationcode

exit(0)

