Created
August 6, 2012 16:53
-
-
Save xnyhps/3276546 to your computer and use it in GitHub Desktop.
WhatsApp messages db to Adium logs
This file contains hidden or 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
| require "luarocks.loader" | |
| require "lsqlite3" | |
| require "luaxml" | |
| require "posix" | |
| -- CREATE TABLE chat_list (_id INTEGER PRIMARY KEY AUTOINCREMENT, key_remote_jid TEXT UNIQUE, message_table_id INTEGER); | |
| -- CREATE TABLE messages (_id INTEGER PRIMARY KEY AUTOINCREMENT, key_remote_jid TEXT NOT NULL, key_from_me INTEGER, key_id TEXT NOT NULL, status INTEGER, needs_push INTEGER, data TEXT, timestamp INTEGER, media_url TEXT, media_mime_type TEXT, media_wa_type TEXT, media_size INTEGER, media_name TEXT, latitude REAL, longitude REAL, thumb_image TEXT, remote_resource TEXT, received_timestamp INTEGER, send_timestamp INTEGER, receipt_server_timestamp INTEGER, receipt_device_timestamp INTEGER, raw_data BLOB); | |
| -- CREATE UNIQUE INDEX messages_key_index on messages (key_remote_jid, key_from_me, key_id); | |
| local self = "[email protected]"; | |
| local db = sqlite3.open("msgstore.db"); | |
| posix.mkdir("WhatsApp." .. self); | |
| for contact in db:nrows("SELECT key_remote_jid FROM messages GROUP BY key_remote_jid") do | |
| local chat = xml.new("chat"); | |
| chat.service = "WhatsApp"; | |
| chat.account = self; | |
| local jid = contact.key_remote_jid; | |
| local stmt = db:prepare("SELECT * FROM messages WHERE key_remote_jid IS ? ORDER BY timestamp"); | |
| local fst_timestamp = nil; | |
| stmt:bind_values(jid); | |
| for row in stmt:nrows() do | |
| local message = chat:append("message"); | |
| message[1] = row.data; | |
| if row.key_from_me == 1 then | |
| message.sender = self; | |
| else | |
| message.sender = row.key_remote_jid; | |
| end | |
| message.time = os.date("!%Y-%m-%dT%H:%M:%S+00:00", row.timestamp / 1000); | |
| if not fst_timestamp then fst_timestamp = message.time; end | |
| print(row.data); | |
| end | |
| posix.mkdir("WhatsApp." .. self .. "/" .. jid); | |
| posix.mkdir("WhatsApp." .. self .. "/" .. jid .. "/" .. jid .. " (" .. fst_timestamp .. ").chatlog"); | |
| local file = io.open("WhatsApp." .. self .. "/" .. jid .. "/" .. jid .. " (" .. fst_timestamp .. ").chatlog/" .. jid .. " (" .. fst_timestamp .. ").xml", "wb"); | |
| file:write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>") | |
| file:write(tostring(chat)); | |
| file:close(); | |
| print(tostring(chat)); | |
| end | |
| db:close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment