[Main]
base_dir = /home/user1/public_html/stations/
www_base = /stations/
template_file = /home/user2/cron/graphs/template.html
destination = /home/user2/public_html/stations/graphs.html
contact_address = user3@website.com
network_url = http://web-stations.org
[Stations]
stn1 = Station 1
stn2 = Station 2
stn3 = Station 3
etc...
[Graphs]
diag = Diagnostics
air = Air Temperature
bar = Barometric Pressure
etc...
import os, sys
import time
from datetime import datetime, date, timedelta
import pytz
import fileinput
import ConfigParser
from configobj import ConfigObj
try:
cfg = sys.argv[1]
except:
print 'Error: pls include config file!'
sys.exit()
parser = ConfigParser.SafeConfigParser()
parser.read(cfg)
destination = parser.get('Main', 'destination')
network_url = parser.get('Main', 'network_url')
source_dir = parser.get('Main', 'source_dir')
target = open(destination, 'w')
station_list = [ 'stn1', 'stn2', 'stn3', 'stn4', 'stn5', \
'stn6', 'stn7', 'stn8', 'stn9', 'stn10' ]
class SourceError(Exception):
log = "Sorry, no source logs were found"
class Station:
def __init__(self, source, option):
self.source = source
self.option = option
self.current_date = current_date
self.InDiag = InDiag
self.line_list = line_list
self.last_line = last_line
self.last_ts = last_ts
self.ts = ts
self.time_diff = time_diff
self.station_list = station_list
self.period_list = period_list
self.link_colors = link_colors
self.result = result
def procIni(self, source, option):
print 'option', option
InDiag = open(self.source, 'r')
line_list = InDiag.readlines()
last_line = line_list[len(line_list)-1]
last_ts = last_line[1:20]
(rYr, rMo, rDay, rHr, rMin, rSec) = time.strptime(last_ts, "%Y-%m-%d %H:%M:%S")[0:6]
ts = datetime(rYr, rMo, rDay, rHr, rMin, rSec, tzinfo=pytz.timezone('America/Anchorage'))
time_diff = current_date - ts
print 'time_diff', time_diff
for stn in station_list:
if option == stn:
if float(time_diff.days) == -1:
delay = 0
else:
delay = float(time_diff.days)
delay = int(round(delay, 0)
return stn, delay
def procStns(stn, delay):
period_list = [ 7, 14, 30, 60, 120, 180, 360 ]
link_colors = [ 'red', 'blue' ]
for period in period_list:
result = delay - period
# process station files to figure out which results are
# positive and negative, find the highest negative
# result for each time increment by station,
# then assign link colors to the
# file links based on the numbers
if __name__ == '__main__' :
config = ConfigObj(cfg)
current_date = datetime.now(pytz.timezone('America/Anchorage'))
for option in config['Stations']:
diag_path = source_dir + option + '/' + option
if option in [ 'stn1', 'stn2', 'stn3' ]:
source = diag_path + '_diag.dat'
elif option == 'stn4':
source = diag_path + '_diagnotics.dat'
else:
source = diag_path + '_hourlydiag.dat'
if source:
try:
Station(source, option)
except SourceError:
print SourceError.log
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE