Add a redshift wrapper with some lat/lon
This commit is contained in:
parent
9dbf117e7b
commit
9aea7db0d6
33
redshift-wrapper
Executable file
33
redshift-wrapper
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
|
||||
main() {
|
||||
exec redshift -l "$(__get_lat_lon)"
|
||||
}
|
||||
|
||||
__get_lat_lon() {
|
||||
: "${IP_LOOKUP_URL:=https://eeloo.humans.rip/ip}"
|
||||
: "${GEOIP_LOOKUP_HOST:=http://api.geoiplookup.net}"
|
||||
|
||||
local ipaddr
|
||||
ipaddr="$(curl -sSL "${IP_LOOKUP_URL}")"
|
||||
|
||||
local geoip_xml
|
||||
geoip_xml="$(curl -sSL "${GEOIP_LOOKUP_HOST}?query=${ipaddr}")"
|
||||
|
||||
__extract_lat_long "${geoip_xml}"
|
||||
}
|
||||
|
||||
__extract_lat_long() {
|
||||
python <<EOPYTHON
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
from xml.dom.minidom import parseString as parse_xml_string
|
||||
dom = parse_xml_string("""${1}""")
|
||||
lat = dom.getElementsByTagName('latitude')[0].firstChild.data
|
||||
lon = dom.getElementsByTagName('longitude')[0].firstChild.data
|
||||
print('{}:{}'.format(lat, lon))
|
||||
EOPYTHON
|
||||
}
|
||||
|
||||
main "${@}"
|
Loading…
Reference in New Issue
Block a user