Is this what you are looking for ??
import tailer
# Get the last line of the EasyWeater.dat file
# This is a little strange - line[1] holds the data
line = tailer.tail(open('c:\Weather\NewWeather\EasyWeather.dat'), 1)
# f = open('c:\Weather\NewWeather\EasyWeather.las', 'w')
# f.write(line[1])
# f.close()
i=0
for value in line[1].split(','):
if i == 2:
stamp = value.strip()
if i == 6:
humidity = value.strip()
if i == 7:
temperature = value.strip()
if i == 11:
pressure = value.strip()
if i == 12:
wind_speed = value.strip()
if i == 14:
gust = value.strip()
if i == 16:
wind_dir = value.strip()
if i == 21:
rain_h = value.strip()
if i == 22:
rain_d = value.strip()
i = i + 1
# Constuct timestamp
# Uses current date as that is easier. This could result in an error near midnight
# but UIView should reject that record.
from datetime import date
now = date.today()
stamp_date = now.strftime("%b %d %Y")
stamp_time = stamp[11:16]
UIView_stamp = stamp_date+" "+stamp_time
# Wind direction (convert from 0 - 15 to degrees)
wind = float(wind_dir)
wind = int((wind * 22.5) + 0.5)
wind_dir = str(wind)
wind_dir = wind_dir.zfill(3)
# Wind speed (convert meters/sec to mph)
speed = float(wind_speed)
speed = int((speed * 2.2369) + 0.5)
wind_speed = str(speed)
wind_speed = wind_speed.zfill(3)
# Gust speed (convert meters/sec to mph)
speed = float(gust)
speed = int((speed * 2.2369) + 0.5)
gust = str(speed)
gust = gust.zfill(3)
# Temperature (convert C to F)
temp = float(temperature)
temp = int((temp * 9 / 5) + 32.5)
temperature = str(temp)
temperature = temperature.zfill(3)
# Pressure
press = float(pressure)
press = press * 10
press = int(press)
pressure = str(press)
# Rain last hour (convert mm to 1/100 inch)
rain = float(rain_h)
rain = (rain * 3.937) + 0.5
rain = int(rain)
rain_h = str(rain)
rain_h = rain_h.zfill(3)
# Now set it to ... anyway because of the EasyWeather bug
rain_h = '...'
# Rain last 24 hours (convert mm to 1/100 inch)
rain = float(rain_d)
rain = (rain * 3.937) + 0.5
rain = int(rain)
rain_d = str(rain)
rain_d = rain_d.zfill(3)
# Now set it to ... anyway because of the EasyWeather bug
rain_d = '...'
f = open('c:\Weather\NewWeather\wx_ext.txt', 'w')
f.write(UIView_stamp+'\n')
second_line = wind_dir.zfill(3)+'/'+wind_speed+'g'+gust+'t'+temperature+'r'+rain_h+'p'+rain_d+'P...h'+humidity.zfill(2)+ 'b'+ pressure.zfill(5)
f.write(second_line)
f.close()