#!/usr/bin/python
import time

def generate(content):
    timestamp=content.split('@@')[0].split('@')[1]
#    print 'timestamp:\t',"-"+timestamp+"-"
    data=content.split('@@')[1]
#    print 'data:\t\t',data
    status.write(time.strftime('%Y-%m-%d %X',time.localtime(float(timestamp)))+'\n')
    pointer=0
    for number in data.split():
        if pointer >= len(ruler):
            return 1
        print pointer,number,ruler[pointer]
        if int(number)<0:
            status_line='<img src="0">'
        elif int(number)<int(ruler[pointer][1]):
            status_line='<img src="1">'
        elif int(number)<int(ruler[pointer][2]):
            status_line='<img src="2">'
        else:
#            status_line='<img src="3"><embed src="alert" width=0 height=0 type="audio/mpeg" loop=1 autostart="true"></embed>'
            status_line='<img src="3"><embed src="alert" width=0 height=0 type="audio/mpeg">'
        status.write(status_line+ruler[pointer][0]+' : '+number+'\n')
#        status.write(str(ruler[pointer])+'\n')
        pointer+=1
    return 0


log_file='SMART.log'
status_file='SMART.status'
criteria_file='SMART.criteria'

log=open(log_file,'r')
status=open(status_file,'w')
criteria=open(criteria_file,'r')

ruler=[]
for line in criteria.readlines():
    rule=line.split('\n')[0]
    ruler.append(rule.split())
#print 'ruler:\t\t',ruler
criteria.close

for line in log.readlines():
    content=line.split('\n')[0]
generate(content)

log.close
status.close
