Example #1
0
def send_alert(alert,row):
    sent = 0
    if alert['state'] + timedelta(minutes = int(alert['cut_off'])) < row['timestamp']:
        connection, cur = open_connection()
        cur.execute("SELECT * FROM recipient JOIN alert_recipient WHERE alert_recipient.alert_id ="+ str(alert['alert_id']))
        recipients = cur.fetchall()
        # unit_name; 
        cur.execute("SELECT * FROM unit WHERE unit_id = " + str(row['unit_id']))
        unit_name = cur.fetchall()[0]['name']
        #format; 
        cur.execute("SELECT * FROM alert_format WHERE alert_format.type = '" + alert['type'] +"'")
        fmt = cur.fetchall()[0]['format']
        
        for recipient in recipients:
            if recipient['email'] != '':
                if debug == True: print 'send_alert: send email'
                mail_args = {"nickname":recipient['nickname'], 
                             "unit_name":str(unit_name), 
                             "speed":row['speed'], 
                             "location":str(row['utm_lat']) + "%20" + str(row['utm_long']),
                             "format": str(fmt),
                             "timestamp":row['timestamp'],
                             "to":recipient['email']}
                
                mail(mail_args)
                             
            if recipient['sms_number'] != '':
                print 'send_alert: send sms'
        cur.execute("UPDATE  `gpstracker`.`alert` SET  `state` =  '" + str(row['timestamp']) + "' WHERE `alert`.`alert_id` = '" + str(alert['alert_id']) + "';")
        cur.close()
        connection.close()
        sent = 1
        
    return sent
Example #2
0
def sendMail(locationLog, alert, recipient):
    mail_args = {    "nickname" : recipient.nickname,
                     "driver_name" : locationLog.driver,
                     "car_name" : locationLog.car,
                     "speed" : str(locationLog.speed),
                     "location" : "%s%%20%s" % (locationLog.lat,locationLog.long),
                     "format" : getAlertFormat(alert,"email"),
                     "timestamp" : str(locationLog.timestamp),
                     "to" : str(recipient.email)}
    mail(mail_args)