Skip to content

Instantly share code, notes, and snippets.

@scintill
Last active June 28, 2020 21:43
Show Gist options
  • Save scintill/ce88c589a8f7af4ac372a3661d8d7096 to your computer and use it in GitHub Desktop.
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)
<?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