-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo.py
executable file
·35 lines (28 loc) · 860 Bytes
/
geo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# coding: utf-8
'''Get the location of the computer, based on the IP address.'''
import requests
import utm as utmc
def __get_ipinfo():
return requests.get('https://ipinfo.io/geo').json()
def latlons():
'''Return latitude and longitude as str'''
ipinfo = __get_ipinfo()
lat, lon = ipinfo['loc'].split(',')
return lat, lon
def latlonf():
'''Return latitude and longitude as floats'''
ipinfo = __get_ipinfo()
lat, lon = ipinfo['loc'].split(',')
return float(lat), float(lon)
def utmf():
'''Return UTM coordinates as floats'''
lat, lon = latlonf()
utm_result = utmc.from_latlon(lat, lon)
return utm_result[0], utm_result[1]
def utms():
'''Return UTM coordinates as str'''
utm_e, utm_n = utmf()
return str(utm_e), str(utm_n)
if __name__ == '__main__':
print(utmf())