Skip to content

Commit

Permalink
Einführung mehrerer Gaswaagen
Browse files Browse the repository at this point in the history
Schreiben der Files mit einer Gaswaagen Nummer
  • Loading branch information
spitzlbergerj authored Jan 8, 2023
1 parent 21105ac commit 6aa0891
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions gas-weight/gasScale2file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ def cleanAndExit():
print ("Bye!")
sys.exit()

def write2file(wert, relativ):
def write2file(gasCylinderNumber, wert, relativ):
try:
dateiName = "/home/pi/CaravanPi/values/gasScale"
strGasScaleBez = "gasScale"+'{:.0f}'.format(gasCylinderNumber)
dateiName = "/home/pi/CaravanPi/values/"+strGasScaleBez
file = open(dateiName, 'a')
str_from_time_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
strWert = '{:.0f}'.format(wert)
strRelativ = '{:.0f}'.format(relativ)
file.write("\n"+ "gasScale " + str_from_time_now + " " + strWert + " " + strRelativ)
file.write("\n"+ strGasScaleBez + " " + str_from_time_now + " " + strWert + " " + strRelativ)
file.close()
return 0
except:
# Schreibfehler
print ("Die Datei konnte nicht geschrieben werden.")
print ("Die Datei " + dateiName + " konnte nicht geschrieben werden.")
return -1

def main():
Expand Down Expand Up @@ -140,7 +141,7 @@ def main():
print ("Nettogewicht Gas: ", nettoWeight)
print ("Nettofüllgrad: ", nettoLevel)

write2file(nettoWeight, nettoLevel)
write2file(gasCylinderNumber, nettoWeight, nettoLevel)

except (KeyboardInterrupt, SystemExit):
cleanAndExit()
Expand Down

0 comments on commit 6aa0891

Please sign in to comment.