2to3 on degree2decimal.py
[plewww.git] / googlemap / degree2decimal.py
1 #!/usr/bin/env python3
2 # transforms a degree notation like
3 # 43:36:56.32 (43 degrees 36 minutes 56.32 seconds) 
4 # into a decimal notation
5
6 import sys
7 import re
8 pattern="^(-*\d+):(\d+):([\d\.]+)$"
9 matcher=re.compile(pattern)
10
11 minute=1./60
12 second=1./3600
13
14 def translate (coord):
15     r=matcher.match(coord)
16     if not r:
17         print('failed to parse',coord,'pattern=',pattern)
18     else:
19         (deg,min,sec)=list(map(float,r.groups()))
20 #        print 'deg',deg,'min',min,'sec',sec
21         if (deg>0):
22             print(coord,'->',deg+min*minute+sec*second)
23         else:
24             print(coord,'->',deg-min*minute-sec*second)
25             
26
27 def main():
28     for arg in sys.argv[1:]:
29         translate(arg)
30     
31 if __name__ == '__main__':
32     main()