# Process AWOS METAR file 

import re, tempfile, os, mx.DateTime
gmt = mx.DateTime.gmt()

data = {}
for line in open('/mesonet/data/incoming/iaawos_metar.txt', 'r'):
    m = re.match("METAR K(?P<id>[A-Z]{3})", line)
    if not m:
      continue
    d = m.groupdict()
    data[ d['id'] ] = line
    
fd, path = tempfile.mkstemp()
os.write(fd,  '000\nNZUS99 KDMX %s\n' % (gmt.strftime("%d%H%M"),)) 
for id in data.keys():
    os.write(fd, '%s=\n' % (data[id].strip(),))
os.close(fd)
os.system("/home/ldm/bin/pqinsert -p 'LOCDSMMETAR.dat' %s" % (path,)) 
os.remove(path) 

@@ -341,16 +341,18 @@
 ,  '000%5C
+r%5C
 nNZUS99 
@@ -359,16 +359,18 @@
 KDMX %25s%5C
+r%5C
 n' %25 (gm
@@ -439,16 +439,18 @@
 d, '%25s=%5C
+r%5C
 n' %25 (da

convert to DOS