Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add header to csv files and deliminate with commas #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions brewpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,23 @@ def renameTempKey(key):
#write csv file too
csvFile = open(localCsvFileName, "a")
try:
lineToWrite = (time.strftime("%b %d %Y %H:%M:%S;") +
str(newRow['BeerTemp']) + ';' +
str(newRow['BeerSet']) + ';' +
str(newRow['BeerAnn']) + ';' +
str(newRow['FridgeTemp']) + ';' +
str(newRow['FridgeSet']) + ';' +
str(newRow['FridgeAnn']) + ';' +
str(newRow['State']) + ';' +
#is this a new csv file?
#opened with append so is at the end of the file. If tell returns 0 there is no data in the file (new file)
if csvFile.tell() == 0:
#add header
lineToWrite = 'DateTime,BeerTemp,BeerSet,BeerAnn,FridgeTemp,FridgeSet,FridgeAnn,State,RoomTemp\n'
csvFile.write(lineToWrite)
except KeyError, e:
logMessage("KeyError in line from controller: %s" % str(e))
try:
lineToWrite = (time.strftime("%b %d %Y %H:%M:%S,") +
str(newRow['BeerTemp']) + ',' +
str(newRow['BeerSet']) + ',' +
str(newRow['BeerAnn']) + ',' +
str(newRow['FridgeTemp']) + ',' +
str(newRow['FridgeSet']) + ',' +
str(newRow['FridgeAnn']) + ',' +
str(newRow['State']) + ',' +
str(newRow['RoomTemp']) + '\n')
csvFile.write(lineToWrite)
except KeyError, e:
Expand Down