-
Notifications
You must be signed in to change notification settings - Fork 0
/
metar.py
31 lines (28 loc) · 836 Bytes
/
metar.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
import re
records = []
with open('metar') as f:
record = ''
keep = False
for line in f.readlines():
if line[0] == '2':
if keep:
records.append(record)
if line[13:18] == 'METAR':
record = line.rstrip()
keep = True
else:
keep = False
if line[0] == ' ':
record += ' ' + line.lstrip().rstrip()
for r in records:
t = "-".join([r[0:4], r[4:6], r[6:8]]) + " " + ":".join([r[8:10], r[10:12]])
l = r[19:23]
try:
v = re.search('1?(\d \d/)?\d(?= ?SM)', r).group(0)
except:
""" Visibility must be missing or broken """
continue
if re.search('/', v):
v = str(int(v[0]) + float(v[2]) / float(v[4]))
print("\t".join([t, l, v]))
#print("\n".join(records))