From bcb9ca95518126131a16fcde894fc8765e7ab010 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 21 Jan 2016 22:35:24 +0100 Subject: more explore --- bin/tools/generate_explore.php | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bin/tools/generate_explore.php (limited to 'bin') diff --git a/bin/tools/generate_explore.php b/bin/tools/generate_explore.php new file mode 100644 index 000000000..9fe1f4bbd --- /dev/null +++ b/bin/tools/generate_explore.php @@ -0,0 +1,65 @@ + + * @copyright Bernhard Posselt 2016 + */ + +/** + * This is used for generating a JSON config section for a feed by executing: + * php -f generate_authors.php www.feed.com + */ + +require_once __DIR__ . '/../../vendor/autoload.php'; + +if (count($argv) < 2 || count($argv) > 3) { + print('Usage: php -f generate_explore http://path.com/feed [vote_count]'); + print("\n"); + exit(); +} elseif (count($argv) === 3) { + $votes = $argv[2]; +} else { + $votes = 100; +} + +$url = $argv[1]; + +try { + $config = new PicoFeed\Config\Config(); + $reader = new PicoFeed\Reader\Reader($config); + $resource = $reader->discover($url); + + $location = $resource->getUrl(); + $content = $resource->getContent(); + $encoding = $resource->getEncoding(); + + $parser = $reader->getParser($location, $content, $encoding); + + $feed = $parser->execute(); + + $favicon = new PicoFeed\Reader\Favicon($config); + + $result = [ + "title" => $feed->getTitle(), + "favicon" => $favicon->find($url), + "url" => $feed->getSiteUrl(), + "feed" => $feed->getFeedUrl(), + "description" => $feed->getDescription(), + "votes" => $votes + ]; + + if ($feed->getLogo()) { + $result["image"] = $feed->getLogo(); + } + + print(json_encode($result, JSON_PRETTY_PRINT)); + +} catch (\Exception $ex) { + print($ex->getMessage()); +} + +print("\n"); \ No newline at end of file -- cgit v1.2.3