Sunday, June 14, 2009

Weather report - Update

CHANGELOG

TODO:

Fix the need to be in the current directory for the file to be located
RSS capability nearly works. Just add an option for auto-detection. (i think i have done this now)
To save the repeated entering of options, load the config from a file
Use son, father, grandfather backup scheme to search for the weather in a file LESS THAN A WEEK OLD

Done:

Made bash script to automate everything.


0.3 - Lots added

Function to find the position of the nth colon
A parsing function that extracts the 3 relevant bits of information from the relevant line - success
0.2 - More features and bugfixes.
Allows the user to specify is the serial communication functions are on or off. This fixed the issue of the program trying to write to a serial device in /dev/ that isn't there.
Moved the weather file to the same directory.
Allows the users to overwrite which file the program gets its data from.
Changed "4" to "3" in data file name. Also fixed in automator script.
Added a function to extract the general summery from the relevant line.

0.1 - First Semi-Functional Build
Works out what day it is.
Allows the user to add a dayshift to skip to other days.
Outputs relevant line of file.
Sends a serial command to the arduino to display a red LED for failure and a green LED for success.


#!/usr/bin/python
# Filename : weather1.py

import datetime
from datetime import date

enableser = bool(input("Enable serial, (True or False) : "))
if enableser:
import serial
ser = serial.Serial('/dev/tty.usbserial-A8004Iyv', 9600)

import time

def getday():
dayshift = int(raw_input("Enter dayshift, (eg 0 for today,1 for tomorrow.) : "))
now = datetime.datetime.now()
year = now.year
month = now.month
day = now.day + dayshift
dayofweek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saterday', 'Sunday']
daytoday = dayofweek[date.weekday(date(year,month,day))]
return daytoday

def findcolon(no):
for x in range(1, len(strweather)):
if strweather[x] == ':' :
no =no -1
if no == 0:
return x
def parseline(str):
if 'xml' in file.name:
minus = 6
else:
minus = 1
strsky = str[ findcolon(1)+2 : str.index(',') ]
print strsky
strmax = str[ findcolon(2)+2 : str.index("C") -minus]
print strmax
strmin = str[ findcolon(3)+2 : str.rindex("C") -minus]
print strmin

today= getday()
fileoverride = bool(input("Override default file, (True or False) : "))
if fileoverride:
newfile = raw_input("Enter the path for the file : ")
file = open(newfile, "r")
else:
file = open("Next3DaysRSS.xml", "r")

for line in file:
if today in line:
strweather = line
occurs = True
break
else:
occurs = False
print "The day is", today
if occurs:
print strweather
if enableser:
ser.write("Y")
parseline(strweather)
else:
print today, "is not in the file"
if enableser:
ser.write("N")





No comments:

Post a Comment