Created
July 7, 2017 02:52
-
-
Save mattvh/b269806b479506b074e2e6b990080e95 to your computer and use it in GitHub Desktop.
Turns an iMessage conversation from an iPhone backup into an HTML transcript. MIT license.
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
# Converts an iPhone SMS.db file into HTML | |
# Mac: Library > Application Support > MobileSync > Backup | |
# Windows: C:\Users\<user name>\AppData\Roaming\Apple Computer\MobileSync\Backup | |
# Find the folder with the most recently modified date and open it. | |
# Locate the 3d0d7e5fb2ce288813306e4d4636395e047a3d28 file and copy it to the location of this script. | |
# Rename the file to "db.sqlite" | |
# Replace HANDLE_GOES_HERE with the phone number/etc identifying the other party in the DB. | |
# Run the script. | |
require "sqlite3" | |
db = SQLite3::Database.new "db.sqlite" | |
puts "Loading messages..." | |
messages = [] | |
db.execute( "SELECT datetime(message.date, 'unixepoch', '+31 years', '-6 hours'), handle.id, is_from_me, message.text FROM message, handle WHERE message.handle_id = handle.ROWID AND handle.id = 'HANDLE_GOES_HERE';" ) do |row| | |
puts row.inspect | |
msg = { | |
date: row[0], | |
who: if row[2] == 1 then 'Me' else 'Them' end, | |
text: row[3] | |
} | |
puts "<#{msg[:who]}>\t#{msg[:text]}" | |
messages.push(msg) | |
end | |
puts "Writing to file..." | |
f = File.open("log.html", "w") | |
f.write('<!DOCTYPE html>') | |
f.write('<html><head>') | |
f.write('<meta charset="utf-8">') | |
f.write('<title>iMessage Transcript</title>') | |
f.write('<style>') | |
f.write('body { font-family: sans-serif; font-size: 16px; line-height: 1.1; width: 500px; margin: 0 auto; }') | |
f.write('.msg { margin: 16px 0; }') | |
f.write('.who { display: block; margin-bottom: 5px; }') | |
f.write('.text { display: block; margin-left: 15px; }') | |
f.write('.Matt { color: #2890e2 }') | |
f.write('.Liz { color: #dd41ca }') | |
f.write('</style>') | |
f.write('</head><body>') | |
messages.each do |msg| | |
f.write('<div class="msg">') | |
f.write("<span class='who #{msg[:who]}'><#{msg[:who]}></span> <span class='text'>#{msg[:text]}</span>\n") | |
f.write('</div>') | |
end | |
f.write('</body></html>') | |
f.close | |
puts "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment