comparison conv.py @ 0:fb5784aa45e6 default tip

from monotone. problematic https vs v2 API
author Matt Johnston <matt@ucc.asn.au>
date Sun, 21 Oct 2012 23:03:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fb5784aa45e6
1 #!/usr/bin/env python
2 # This Python file uses the following encoding: utf-8
3
4 import re
5 import sys
6
7 s = """
8 PerthAP: 31°57'34.78"S 115°52'20.29"E
9 WannerooAP: 31°47'26.03"S 115°49'12.34"E
10 Belmont2: 31°57'34.19"S 115°55'42.52"E
11 MitchLand: 31°47'17.81"S 115°46'10.70"E
12 Mystic: 31°46'19.51"S 115°45'43.89"E
13 NHE (Welvis): 31°46'29.52"S 115°49'7.87"E
14 Doubleview: 31°53'41.14"S 115°46'50.86"E
15 BelmontAP: 31°57'4.63"S 115°55'15.38"E
16 Zaphod: 31°46'13.77"S 115°46'11.24"E
17 TIC Hill: 31°49'32.77"S 116°3'51.87"E
18 kaelnorr: 31°40'40.79"S 115°42'58.29"E
19 """
20
21 l = s.split('\n')
22
23 r = re.compile(r'(\d+)°(\d+)\'([\d\.]+)".')
24
25 def coord_to_decimal(coord):
26 lparts = r.match(coord)
27 deg, min, sec = map(float, lparts.groups())
28 val = deg + min/60.0 + sec/(60.0**2)
29
30 return val
31
32 for i in l:
33 try:
34 name, coords = i.split(':')
35
36 lat, long = coords.strip().split()
37
38 lat_dec = -coord_to_decimal(lat)
39 long_dec = coord_to_decimal(long)
40
41 print '"%s": [%f, %f, "%s", ""],' % (name.lower(), lat_dec, long_dec, name)
42
43 except Exception, e:
44 print>>sys.stderr, "Error for line '%s': %s" % (i, e)
45 continue
46
47