Last active
December 3, 2018 19:35
-
-
Save sprintr/de85a99d67aae826611e7ec453c4b40f to your computer and use it in GitHub Desktop.
This is a dirty implementation of a GO SMS Pro's backup reader. Thanks to Waseem Kathia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var fs = require("fs"), | |
xml = require("xml-js"); | |
var content = fs.readFileSync("gosms_sys119.xml", "utf8"); | |
var result = xml.xml2json(content, { compact: true, spaces: 4 }); | |
var styleSent = "color: blue;"; | |
var styleReceived = "color: red;"; | |
var stylePara = "font-family: Calibri; font-size: 11pt;"; | |
var styleHeader = "font-family: Calibri; font-size: 18pt;"; | |
var json = JSON.parse(result); | |
var GoSms = json["GoSms"]; | |
var SMS = GoSms["SMS"]; | |
function formatAMPM(date) { | |
return date.getHours() >= 12 ? 'PM' : 'AM'; | |
} | |
var stage1Data = []; | |
SMS.forEach(function (value, index) { | |
var date = new Date(parseInt(value["date"]["_text"])); | |
var hours = date.getHours(); | |
if (hours >= 12) { | |
hours -= 12; | |
} | |
if (hours == 0) { | |
hours = 12; | |
} | |
var time = hours + ":" + date.getMinutes() + " " + formatAMPM(date) + | |
" " + date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear(); | |
stage1Data[index] = { | |
contactName: value["contactName"]["_text"], | |
time: time, | |
contactNumber: value["address"]["_text"], | |
body: value["body"]["_text"], | |
type: value["type"]["_text"] | |
}; | |
}); | |
var stage2Data = {}; | |
stage1Data.forEach(function (value, index) { | |
var contactName = value["contactName"], | |
contactNumber = value["contactNumber"], | |
time = value["time"], | |
body = value["body"], | |
type = value["type"] == "1" ? "received" : "sent"; | |
if (contactNumber == undefined) { | |
return; | |
} | |
if (stage2Data[contactNumber] == undefined) { | |
stage2Data[contactNumber] = { | |
contactName: contactName, | |
contactNumber: contactNumber, | |
messages: [] | |
}; | |
} | |
stage2Data[contactNumber].messages.push({ | |
body: body, | |
time: time, | |
type: type | |
}); | |
}); | |
var content = ""; | |
Object.keys(stage2Data).forEach(function (value, index) { | |
var data = stage2Data[value], | |
contactName = data["contactName"], | |
contactNumber = data["contactNumber"], | |
messages = data["messages"]; | |
content += "<h2 style=\""+styleHeader+"\">" + contactName + " : " + contactNumber + "</h2>\r\n"; | |
messages.forEach(function (value, index) { | |
var body = value["body"], | |
type = value["type"], | |
time = value["time"] | |
if (type == "received") { | |
content += "<p style=\""+stylePara+"\"><b style=\""+styleReceived+"\">" + contactName + "</b> (" + time + ") : " + body + "</p>\r\n"; | |
} | |
else if (type == "sent") { | |
content += "<p style=\""+stylePara+"\"><b style=\""+styleSent+"\">Me</b> (" + time + ") : " + body + "</p>\r\n"; | |
} | |
}); | |
}); | |
fs.writeFileSync("output.html", content, "utf8"); | |
}());\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment