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.pyimport datetimefrom datetime import dateenableser = bool(input("Enable serial, (True or False) : "))if enableser:import serialser = serial.Serial('/dev/tty.usbserial-A8004Iyv', 9600)import timedef getday():dayshift = int(raw_input("Enter dayshift, (eg 0 for today,1 for tomorrow.) : "))now = datetime.datetime.now()year = now.yearmonth = now.monthday = now.day + dayshiftdayofweek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saterday', 'Sunday']daytoday = dayofweek[date.weekday(date(year,month,day))]return daytodaydef findcolon(no):for x in range(1, len(strweather)):if strweather[x] == ':' :no =no -1if no == 0:return xdef parseline(str):if 'xml' in file.name:minus = 6else:minus = 1strsky = str[ findcolon(1)+2 : str.index(',') ]print strskystrmax = str[ findcolon(2)+2 : str.index("C") -minus]print strmaxstrmin = str[ findcolon(3)+2 : str.rindex("C") -minus]print strmintoday= 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 = lineoccurs = Truebreakelse:occurs = Falseprint "The day is", todayif occurs:print strweatherif enableser:ser.write("Y")parseline(strweather)else:print today, "is not in the file"if enableser:ser.write("N")
No comments:
Post a Comment