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