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

if __name__ == '__main__':
    db=mysql()
    if len(sys.argv)>1:
        idemail=sys.argv[1]
        dataemail=db.loadAssoc("SELECT * from tb_kirim_email where id=%s and status=0 ",[str(idemail)])
        
        if dataemail.has_key("email"):
            print dataemail['email']
            kirimem = kirimemail()
            statusemail=kirimem.kiripesan(dataemail['email'],dataemail['subject'],dataemail['pesan'])
            if (statusemail==True):
                print "ok"
                db.query("update tb_kirim_email set tanggal_kirim=NOW(),status=1 where id=%s",[str(idemail)])