Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kindle "My Clippings.txt" splitter
#!/usr/bin/php
<?php
if (empty($argv[2])) {
throw new Exception('usage: <this file> "/path/to/My Clippings.txt" /path/to/ouputfiles');
}
$myClippingsFile = $argv[1];
$splitDir = $argv[2];
$bookAndNotes = array();
// read lines
$notes = explode("==========", file_get_contents($myClippingsFile));
if (empty($notes)) {
throw new Exception("empty or wrong file specified");
}
foreach ($notes as $note) {
// split title and text
$lines = array_slice(explode("\n", $note), 1);
$title = array_shift($lines);
$title = preg_replace('/([^a-z0-9- ])/i', '', $title);
$text = implode("\n", $lines);
// append to file name if the same note does not exist already
$fileName = __DIR__ . "/notes/notes_$title";
if ($text && strpos(@file_get_contents($fileName), $text) === false) {
file_put_contents($fileName, $text, FILE_APPEND);
}
}
@elvisciotti

This comment has been minimized.

Copy link
Owner Author

elvisciotti commented Jul 9, 2012

install from the shell (Mac and Linux)

sudo wget -O /usr/local/bin/kindle-splitter https://gist.github.com/raw/1783585/423159779c1bb2d810004444aa49dc2bf363b55c/kindle-spit-by-book.php && chmod +x /usr/local/bine/kindle-splitter

use

mkdir ~/splittedKindleClippings/
kindle-splitter /media/Kindle/documents/My\ Clippings.txt ~/splittedKindleClippings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.