# -*- coding: cp1250 -*-
import subprocess
import datetime
import time
now = datetime.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M")
zapsano  = 0
soubor = file('log.html','a')  
konec=0

text_bad_start = "<span style ='color : red'> "
text_bad_konec = "</span></br>"

text_test_start = "<span style ='color : grey'> "
text_test_konec = "</span></br>"

print "Mereni zacalo \nscript napsal Re4DeR - re4der.info."

while konec!=1: 
    test = "ping 195.47.235.3"
    process = subprocess.Popen(test, shell=True, stdout=subprocess.PIPE)
    process.wait()
    vysledek = process.returncode  
    

    if vysledek == 0:
       # print "ok"
        if zapsano == 60:
            zapis = text_test_start + now + " - test(OK) " + text_test_konec
            soubor.write(zapis) 
            zapsano  = 0
          
    else:
        #print "vypadek"
        #print now
        zapis = text_bad_start + now + " - výpadek " + text_bad_konec
        soubor.write(zapis) 

    soubor.flush()

    time.sleep(30)
    zapsano = zapsano + 1

