#!/usr/bin/env python
import urllib,json,string
from kirimemail import kirimemail
from mysql import mysql
import sys

if __name__ == '__main__':
    db=mysql()
    dataemail=db.loadAll("SELECT * from tb_kirim_email where status=0 ",[])
    if len(dataemail)>0:
        for i in range(len(dataemail)):
            if len(dataemail[i]['email'])>5:
                kirimem = kirimemail()
                statusemail=kirimem.kiripesan(dataemail[i]['email'],dataemail[i]['subject'],dataemail[i]['pesan'])
                if (statusemail==True):
                    print "ok"
                    db.query("update tb_kirim_email set tanggal_kirim=NOW(),status=1 where id=%s",[str(dataemail[i]['id'])])
            else:
                db.query("update tb_kirim_email set tanggal_kirim=NOW(),status=3 where id=%s",[str(dataemail[i]['id'])])