Created
September 19, 2020 19:55
-
-
Save abdumu/df350a6cf18761b3559434847a294503 to your computer and use it in GitHub Desktop.
Convert simplenote to keep format to import into Zoho Notebook. [After exporting notes.zip, add this file inside the folder and run `php simpleNote2ZohoNoteBook.php`
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 | |
mkdir('./Takeout'); | |
mkdir('./Takeout/Keep'); | |
if (!file_exists('./Takeout/Keep')) { | |
die('Please create empty "./Takeout/Keep" folder.'); | |
} | |
$htmlTemplate = '<?xml version="1.0" ?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>{title}</title> | |
</head> | |
<body> | |
<div class="note DEFAULT"> | |
<div class="heading">{time}</div> | |
<div class="title">{title}</div> | |
<div class="content">{content}</div> | |
</div> | |
</body> | |
</html>'; | |
$x = file_get_contents('./source/notes.json'); | |
$r = json_decode($x, true); | |
foreach (['activeNotes', 'trashedNotes'] as $type) { | |
foreach ($r[$type] as $t) { | |
$data = [ | |
'color' => 'DEFAULT', | |
'isTrashed' => $type == 'trashedNotes', | |
'isPinned' => $t['pinned'] ?? false, | |
'title' => '', | |
'textContent' => $t['content'] ?? '', | |
'userEditedTimestampUsec' => date_create($t['lastModified'] ?? $t['creationDate'])->getTimestamp() * 100000, | |
]; | |
$title = ''; | |
if (strpos($t['content'], "\n") !== false) { | |
[$title,] = explode("\n", $t['content'], 2); | |
} | |
$htmlDate = str_replace( | |
['{title}', '{time}', '{content}'], | |
[ | |
$title, | |
date_create($t['lastModified'] ?? $t['creationDate'])->format('M d, Y, h:i:s A'), | |
nl2br($t['content']), | |
], | |
$htmlTemplate | |
); | |
file_put_contents('./Takeout/Keep/' . $t['id'] . '.html', $htmlDate); | |
file_put_contents('./Takeout/Keep/' . $t['id'] . '.json', json_encode($data)); | |
} | |
} | |
exec("zip -r googleKeepFormatNotes.zip Takeout"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment