Last active
June 28, 2020 21:43
-
-
Save scintill/ce88c589a8f7af4ac372a3661d8d7096 to your computer and use it in GitHub Desktop.
Convert Android com.kyakujin.android.tagnotepad to Evernote .enex file (targeting iOS notes app)
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
<?php | |
// # adb backup com.kyakujin.android.tagnotepad | |
// # java -jar ~/Downloads/abe-all.jar unpack backup.ab - 1 | tar -x --strip-components=3 apps/com.kyakujin.android.tagnotepad/db/tagnotepad.db # https://github.com/nelenkov/android-backup-extractor | |
// https://gist.github.com/evernotegists/6116886 | |
// https://github.com/panicsteve/enex-dump/blob/master/enex-dump.php | |
// https://raw.githubusercontent.com/fabiospampinato/enex-dump/master/resources/test.enex | |
function formatDate(DateTimeImmutable $date) { | |
return $date->setTimezone(new DateTimeZone('Etc/UTC'))->format('Ymd\THis\Z'); | |
} | |
function formatContent($plaintext) { | |
$content = '<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>'; | |
$content .= '<div style="white-space: pre">' . htmlspecialchars($plaintext, ENT_XML1) . '</div>'; | |
$content .= '</en-note>]]>'; | |
return $content; | |
} | |
function androidTsToDt($ts) { | |
$ts = (int)($ts / 1000); | |
return new DateTimeImmutable('@'.$ts); | |
} | |
?> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export3.dtd"> | |
<en-export export-date="<?=formatDate(new DateTimeImmutable())?>" application="scintill" version="0.1"> | |
<?php | |
$db = new SQLite3("tagnotepad.db", SQLITE3_OPEN_READONLY); | |
$rows = $db->query('SELECT * FROM notes'); | |
while (($row = $rows->fetchArray(SQLITE3_ASSOC)) !== false) { | |
echo '<note><title>', htmlspecialchars($row['title'], ENT_XML1), '</title>', | |
'<content>', formatContent($row['body']), '</content>', "\n", | |
'<created>', formatDate(androidTsToDt($row['created'])), '</created>', | |
'<updated>', formatDate(androidTsToDt($row['modified'])), '</updated>', | |
'</note>', | |
"\n"; | |
} | |
?> | |
</en-export> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment