ich komme mit einer einfachen if Bedingung in einem cgi script nicht klar. Im Prinzip möchte ich eine Zahl auswerten und je nach Ergebnis eine Variable modifizieren.
Mein script sieht folgendermassen aus:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Debug errors on browser
import cgitb; cgitb.enable()
import sys
import os
import subprocess
from time import *
# Zeitvariable definieren
lt = localtime()
# Variablen definieren
uhrzeit = strftime("%H:%M:%S")
# py_temp Textdatei oeffnen, auslesen und wieder schliessen
file = open('py_temp.txt')
py_temp_data = file.readlines()
file.close()
print 'Content-type: text/html\n\n'
print '<html>'
print '<style>'
print ' p {'
print ' color: black;'
print ' font-size: 24px;'
print ' font-weight: bold;'
print ' }'
print ' .normal {'
print ' color: black;'
print ' }'
print ' .hot {'
print ' color: red;'
print ' }'
print ' .cold {'
print ' color: blue;'
print ' }'
print '</style>'
print '<body>'
print '<p class="normal">aktuelle Uhrzeit: ' + uhrzeit + '</p>'
print '<hr style="color:#ceb98e ; height:2px "/>'
# Fuer jede Zeile eine Ausgabe
for line in py_temp_data:
py_temp_data = line.split("\n")[0]
split_py_temp = py_temp_data.split('*', 1)
output_py_temp = split_py_temp[1]
# line_color = "normal"
# Die Temperatur kalkulieren
split_calc_temp = output_py_temp.split(': ', 1)
calc_temp = split_calc_temp[1]
if calc_temp >= 22.0 :
line_color = "hot"
elif calc_temp <= 19.0 :
line_color = "cold"
else:
line_color = "normal"
break
# Ausgabe der aktuellen Temperatur
print '<p class="' + line_color + '"> ' + output_py_temp + ' Grad</p>'
print '<hr style="color:#ceb98e ; height:2px "/>'
print '</body></html>'
sys.exit(0)
Was mache ich nur falsch?