Skip to content

Instantly share code, notes, and snippets.

@robinmarlow
Last active December 17, 2015 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinmarlow/b2189510b5dea45a9597 to your computer and use it in GitHub Desktop.
Save robinmarlow/b2189510b5dea45a9597 to your computer and use it in GitHub Desktop.
<?php
# download the xml using reader.pl from here:
# https://gist.github.com/lotrfan/28c4a266468bb7658e95
#
# usage: php readerXML_to_ttrssXML.php input.xml > output.xml
#
# import into tt-rss using the xml input plugin (may need to gzip first if a huge file)
$filename = $argv[1];
$basexml = simplexml_load_file($filename);
echo "<articles schema-version=\"121\">";
##parse for feed information
$feedurl=preg_replace('/^tag.*reader\/feed\//', '', $basexml->id);
$feedtitle =$basexml->title;
foreach ($basexml->entry as $articlexml){
echo "<article>";
echo "<guid><![CDATA[".$articlexml->id."]]></guid>";
echo "<title><![CDATA[".$articlexml->title."]]></title>";
if (strlen($articlexml->summary) > 0) echo "<content><![CDATA[".$articlexml->summary."]]></content>";
else if (strlen($articlexml->content) > 0) echo "<content><![CDATA[".$articlexml->content."]]></content>";
$starred=FALSE;
$read=FALSE;
$tags="";
$tags_array=NULL;
foreach ($articlexml->category as $articlecategory) {
if ($articlecategory['label']=="starred") $starred=TRUE;
if ($articlecategory['label']=="read") $read=TRUE;
#if ($articlecategory['scheme']!="http://www.google.com/reader/") $tags.= strtolower($articlecategory['term']).",";
if ($articlecategory['scheme']!="http://www.google.com/reader/") $tags_array[] = strtolower($articlecategory['term']);
}
if ($starred) echo "<marked><![CDATA[1]]></marked>";
else echo "<marked><![CDATA[0]]></marked>";
#unread not currently parsed by xml importer - but could be added in the future
if ($read) echo "<unread><![CDATA[0]]></unread>";
else echo "<unread><![CDATA[1]]></unread>";
if (count($tags) >1) $tags = implode(',', array_unique($tags_array) );
echo "<score><![CDATA[0]]></score>";
echo "<note><![CDATA[]]></note>";
echo "<link><![CDATA[".$articlexml->link['href']."]]></link>";
echo"<tag_cache><![CDATA[".$tags."]]></tag_cache>";
echo"<label_cache><![CDATA[{\"no-labels\":1}]]></label_cache>";
echo "<feed_title><![CDATA[".$feedtitle."]]></feed_title>";
echo "<feed_url><![CDATA[".$feedurl."]]></feed_url>";
echo "<updated><![CDATA[".$articlexml->updated."]]></updated>";
echo "</article>";
}
echo "</articles>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment