Skip to content

Instantly share code, notes, and snippets.

@artpi
Created January 12, 2018 08:28
Show Gist options
  • Save artpi/a5f1d7c39bc0207e1163f3cb04ae6049 to your computer and use it in GitHub Desktop.
Save artpi/a5f1d7c39bc0207e1163f3cb04ae6049 to your computer and use it in GitHub Desktop.
Download kindle my clippings file and parse them
class MyClippings extends Shortcode {
public $name = "my-clippings";
static $clippings;
static function load_clippings() {
if( ! self::$clippings ) {
self::$clippings = file_get_contents( "https://drive.google.com/uc?export=download&id=[SOME FILE ID FROM Gdrive]" );
}
}
function process( $filter ) {
self::load_clippings();
$items = explode( "==========", self::$clippings );
$highlights = array();
foreach ($items as $index => $item) {
$item = trim( $item );
$lines = explode( "\n", $item );
if( stristr( $lines[ 0 ], $filter ) ) {
$highlight = implode( "<br/>", array_slice( $lines, 3 ) );
$highlight = str_replace( "<br>", "<br/>", $highlight );
$highlight = strip_tags( $highlight, "<br/>" );
$highlight = htmlentities( $highlight );
$highlights[] = "<li>".$highlight."</li>";
}
}
$highlights=implode( "\n", $highlights );
$output = "<ul>
${highlights}
</ul>";
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment