# read/write sensor log

 

import re

 

def c_to_f(num):

    return (num*5.0/9)+32.0

 

# limit data to 40 lines

lines = 40

 

f1 = open(fn_input)

lineList = [f1.next() for _ in range(lines)]

f1.close()

 

patt = re.compile(r"'(.+)'")

readDict = {}

for item in lineList:

    key, value = [s.strip() for s in patt.search(item).group(1).split(",")]

    readDict.setdefault(key, []).append(c_to_f(float(value)))

 

print readDict

 

sensor1List = [item for item in lineList if "'1," in item]

sensor2List = [item for item in lineList if "'2," in item]

 

print c_to_f(float('22.05'))

 

for key in readDict:

    print "Sensor #%s:" % key

    for item in readDict[key]:

        print "    %.4f" % item

 

# This writes key 1 to a logfile

logfile1 = open(r'H:\TEMP\temsys\sensor1_value.txt', 'a')

logfile1.write("\n".join(['\n',]+['%.4f' % item for item in readDict["1"]]))

logfile1.close()

 

# This writes key 2 to a logfile

logfile2 = open(r'H:\TEMP\temsys\sensor2_value.txt', 'a')

logfile2.write("\n".join(['\n',]+['%.4f' % item for item in readDict["2"]]))

logfile2.close()

 

'''

fn_input = r'H:\TEMP\temsys\xxxxxlog.txt'

fn_output = r'H:\TEMP\temsys\xxxxxlog_output.txt'

 

lines = 20

 

f1 = open(fn_input)

lineList = [f1.next() for _ in range(lines)]

f1.close()

 

readList = [float(s.split(',')[1].strip("' \n")) for s in lineList]

readPairs = [(readList[i], readList[i+1]) for i in range(0, len(readList), 2)]

'''

 

'''

f2 = open(fn_output, 'w')

f2.write(''.join(lineList))

f2.close()

'''

 

''' Input file:

Nov 28 17:34:23  76.17.211.244 : '2, 22.05'

Nov 28 17:35:38  76.17.211.244 : '1, 24.67'

Nov 28 17:39:23  76.17.211.244 : '2, 22.69'

Nov 28 17:44:23  76.17.211.244 : '2, 22.35'

Nov 28 17:45:38  76.17.211.244 : '1, 24.64'

Nov 28 17:49:23  76.17.211.244 : '2, 22.05'

Nov 28 17:54:23  76.17.211.244 : '2, 22.48'

Nov 28 17:55:38  76.17.211.244 : '1, 24.55'

Nov 28 17:59:23  76.17.211.244 : '2, 22.16'

Nov 28 18:00:38  76.17.211.244 : '1, 24.52'

Nov 28 18:04:23  76.17.211.244 : '2, 21.85'

Nov 28 18:05:39  76.17.211.244 : '1, 24.49'

Nov 28 18:09:23  76.17.211.244 : '2, 21.59'

Nov 28 18:10:38  76.17.211.244 : '1, 24.42'

Nov 28 18:14:23  76.17.211.244 : '2, 21.71'

Nov 28 18:15:38  76.17.211.244 : '1, 24.38'

Nov 28 18:19:23  76.17.211.244 : '2, 21.58'

Nov 28 18:20:38  76.17.211.244 : '1, 24.37'

Nov 28 18:24:23  76.17.211.244 : '2, 21.34'

Nov 28 18:25:38  76.17.211.244 : '1, 24.32'

Nov 28 18:29:23  76.17.211.244 : '2, 21.15'

Nov 28 18:30:40  76.17.211.244 : '1, 24.26'

Nov 28 18:34:25  76.17.211.244 : '2, 20.97'

Nov 28 18:35:40  76.17.211.244 : '1, 24.22'

Nov 28 18:39:25  76.17.211.244 : '2, 20.82'

Nov 28 18:40:40  76.17.211.244 : '1, 24.15'

Nov 28 18:45:40  76.17.211.244 : '1, 24.10'

Nov 28 18:49:25  76.17.211.244 : '2, 20.57'

Nov 28 18:54:25  76.17.211.244 : '2, 20.45'

Nov 28 18:55:40  76.17.211.244 : '1, 23.99'

Nov 28 18:59:25  76.17.211.244 : '2, 20.35'

Nov 28 19:00:40  76.17.211.244 : '1, 23.94'

Nov 28 19:04:25  76.17.211.244 : '2, 20.22'

Nov 28 19:05:40  76.17.211.244 : '1, 23.88'

Nov 28 19:09:25  76.17.211.244 : '2, 20.11'

Nov 28 19:10:40  76.17.211.244 : '1, 23.83'

Nov 28 19:14:25  76.17.211.244 : '2, 20.00'

Nov 28 19:15:40  76.17.211.244 : '1, 23.76'

Nov 28 19:19:25  76.17.211.244 : '2, 19.91'

Nov 28 19:20:40  76.17.211.244 : '1, 23.72'

Nov 28 19:24:25  76.17.211.244 : '2, 19.84'

Nov 28 19:25:40  76.17.211.244 : '1, 23.70'

Nov 28 19:29:25  76.17.211.244 : '2, 19.76'

Nov 28 19:30:40  76.17.211.244 : '1, 23.66'

Nov 28 19:35:40  76.17.211.244 : '1, 23.62'

Nov 28 19:39:25  76.17.211.244 : '2, 19.75'

Nov 28 19:40:40  76.17.211.244 : '1, 23.59'

Nov 28 19:44:24  76.17.211.244 : '2, 19.91'

Nov 28 19:45:40  76.17.211.244 : '1, 23.59'

Nov 28 19:49:25  76.17.211.244 : '2, 19.81'

Nov 28 19:50:40  76.17.211.244 : '1, 23.56'

Nov 28 19:54:25  76.17.211.244 : '2, 19.71'

Nov 28 19:55:40  76.17.211.244 : '1, 23.55'

Nov 28 19:59:25  76.17.211.244 : '2, 19.95'

Nov 28 20:00:40  76.17.211.244 : '1, 23.57'

Nov 28 20:04:25  76.17.211.244 : '2, 19.95'

Nov 28 20:05:40  76.17.211.244 : '1, 23.58'

Nov 28 20:09:24  76.17.211.244 : '2, 19.81'

Nov 28 20:10:40  76.17.211.244 : '1, 23.56'

Nov 28 20:14:25  76.17.211.244 : '2, 20.48'

'''