Provider timestamp fix

Fixed provider timestamp and made the index.html load a fresh pull of logs.
pull/2/head
Hailey Clark 6 years ago
parent 58113264da
commit 3c14b09e45
  1. 6
      appdb.py
  2. 76
      templates/single.html

@ -52,7 +52,7 @@ def updateMsgStatus(msg_id,status, msg_timestamp):
#UPDATE messages SET delivered='success' WHERE pid='mdr2-46999f9ce19e11e99074722a1f1f4bb4' #UPDATE messages SET delivered='success' WHERE pid='mdr2-46999f9ce19e11e99074722a1f1f4bb4'
db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb) db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb)
cur = db.cursor() cur = db.cursor()
affected_count = cur.execute("UPDATE `messages` SET status=%s, `timestamp`=%s WHERE `pid`=%s",(status, msg_timestamp ,msg_id)) affected_count = cur.execute("UPDATE `messages` SET status=%s, `provider_timestamp`=%s WHERE `pid`=%s",(status, msg_timestamp ,msg_id))
db.commit() db.commit()
db.close() db.close()
return True return True
@ -61,7 +61,7 @@ def updateMsgTimestamp(msg_id,timestamp):
#This changes the timestamp of the msg_id to the timestamp provided by the provider. #This changes the timestamp of the msg_id to the timestamp provided by the provider.
db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb) db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb)
cur = db.cursor() cur = db.cursor()
affected_count = cur.execute("UPDATE `messages` SET `timetsamp`=%s WHERE `pid`=%s",(timestamp,msg_id)) affected_count = cur.execute("UPDATE `messages` SET `provider_timestamp`=%s WHERE `pid`=%s",(timestamp,msg_id))
db.commit() db.commit()
db.close() db.close()
@ -69,7 +69,7 @@ def updateMsgTimestamp(msg_id,timestamp):
def validateFrom(did): def validateFrom(did):
#this statement is here for testing. It bypasses DBs. #this statement is here for testing. It bypasses DBs.
if '17605551212' == did: if '17605551212' == did:
return True return Trueh
db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb) db = pymysql.connect(host=sqlhost, user=sqluser, passwd=sqlpass, db=sqldb)
cur = db.cursor() cur = db.cursor()
cur.execute("SELECT number FROM dids WHERE number=%s LIMIT 1" % did) cur.execute("SELECT number FROM dids WHERE number=%s LIMIT 1" % did)

@ -17,8 +17,10 @@
} else { } else {
$('#charNum').text(160 - len); $('#charNum').text(160 - len);
} }
} }
$("document").ready(function() { $("document").ready(function() {
fromDid = $("#source-num").val();
getNumMessages(fromDid);
// Do something... // Do something...
function setStatus(statusmsg) { function setStatus(statusmsg) {
$("#alert-messages").text(statusmsg); $("#alert-messages").text(statusmsg);
@ -47,56 +49,56 @@
}); });
$( "#chat-form" ).submit(function( event ) { $( "#chat-form" ).submit(function( event ) {
$( "#submit-chat" ).prop("disabled", true); $( "#submit-chat" ).prop("disabled", true);
event.preventDefault(); event.preventDefault();
fromDid = $("#source-num").val(); fromDid = $("#source-num").val();
targetDid = $("#dest-num").val(); targetDid = $("#dest-num").val();
inputchat = $("#input-chat").val(); inputchat = $("#input-chat").val();
if (!$("#input-chat").val()){
setStatus("Empty message field! Cant do this!");
return false;
}
$.ajax({ if (!$("#input-chat").val()){
method: "POST", setStatus("Empty message field! Cant do this!");
url: "/submitMessage",
data: { message: inputchat, fromdid: fromDid, targetdid : targetDid }
}).done(function( msg ) {
dt = new Date();
time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
msgParsed = $.parseJSON(msg);
if (msgParsed.error) {
setStatus('Error! Got "'+ msgParsed.error +'"');
return false; return false;
} }
fromDid = $("#source-num").val();
getNumMessages(fromDid); $.ajax({
setStatus('Success! Got "'+ msg +'"'); method: "POST",
$( "#submit-chat" ).prop("disabled", false); url: "/submitMessage",
clearInput(); data: { message: inputchat, fromdid: fromDid, targetdid : targetDid }
//$("#chat-form").prop('disabled',false); }).done(function( msg ) {
}); dt = new Date();
time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
msgParsed = $.parseJSON(msg);
if (msgParsed.error) {
setStatus('Error! Got "'+ msgParsed.error +'"');
return false;
}
fromDid = $("#source-num").val();
getNumMessages(fromDid);
setStatus('Success! Got "'+ msg +'"');
$( "#submit-chat" ).prop("disabled", false);
$('#charNum').text('160');
clearInput();
});
}); });
$('#test-ajax').click(function() { $('#test-ajax').click(function() {
$.ajax({ $.ajax({
url: '/testAjax', url: '/testAjax',
type: 'GET', type: 'GET',
success: function(response) { success: function(response) {
newHTML = '<div id="msg"><span class="chat-from">SYSTEM</span>: ' + response + '</div>'; newHTML = '<div id="msg"><span class="chat-from">SYSTEM</span>: ' + response + '</div>';
statusHTML = '<div id="alert-messages">Success! Got "'+ response +'"</div>'; statusHTML = '<div id="alert-messages">Success! Got "'+ response +'"</div>';
$("#chat-body").append( newHTML ); $("#chat-body").append( newHTML );
$("#alert-messages").html(statusHTML); $("#alert-messages").html(statusHTML);
}, },
error: function(error) { error: function(error) {
errorHTML = '<div id="msg"><span class="chat-from">SYSTEM</span>: Error ' + error + '</div>'; errorHTML = '<div id="msg"><span class="chat-from">SYSTEM</span>: Error ' + error + '</div>';
statusHTML = '<div id="alert-messages">Error! Got "'+ error +'"</div>'; statusHTML = '<div id="alert-messages">Error! Got "'+ error +'"</div>';
$("#chat-body").append( errorHTML ); $("#chat-body").append( errorHTML );
$("#alert-messages").html(statusHTML); $("#alert-messages").html(statusHTML);
} }
}); });
}); });
}); });
</script> </script>
</head> </head>
<body> <body>

Loading…
Cancel
Save