Google Reader export to bookmarks.htm

by on November 3, 2011


I was one of the small group of Google Reader users who actively used the sharing functionality before Google killed it with their latest upgrade. While the number of people I shared with was small, the quality was incredibly high. I don’t blame Google for wanting to consolidate their social graphs (makes sense to me), but I will miss the conversations I had there.

A friend asked me if I knew how to export the shared items JSON file to a standard bookmarks.htm file. I didn’t, but I managed to whip up a quick PHP script to do the trick. Here’s the code for anyone who is interested.

<?php

// bump this limit up as it can be quite memory intensive if you have a lot of shared items
ini_set('memory_limit', '64M');

// update to use your own file here
$json_file = "/tmp/shared-items.json";

// output the std header
// http://msdn.microsoft.com/en-us/library/aa753582(v=vs.85).aspx
echo <<< EOT
<!DOCTYPE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>
EOT
;

$json = json_decode(file_get_contents($json_file));
echo "<DL>\n\t<DT>";
foreach ($json->items as $item) {
    echo '\t<A HREF="'.$item->alternate[0]->href.'" ADD_DATE="'.$item->published.'" LAST_VISIT="'.round($item->crawlTimeMsec/1000).'" LAST_MODIFIED="'.$item->updated.'">'.utf8_decode($item->title).'</A>\n';
}
echo "</DL>";

?>