Created
January 12, 2018 08:28
-
-
Save artpi/a5f1d7c39bc0207e1163f3cb04ae6049 to your computer and use it in GitHub Desktop.
Download kindle my clippings file and parse them
This file contains 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
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