From 71ba5a3ad1a1c9d867af68e72a4a19acd9ffe08d Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Wed, 6 Mar 2019 13:10:37 +0100 Subject: Fix generation commands and make them available in ./occ (#402) --- bin/tools/generate_authors.php | 10 +++- bin/tools/generate_explore.php | 114 ++++++++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 42 deletions(-) mode change 100644 => 100755 bin/tools/generate_authors.php mode change 100644 => 100755 bin/tools/generate_explore.php (limited to 'bin') diff --git a/bin/tools/generate_authors.php b/bin/tools/generate_authors.php old mode 100644 new mode 100755 index 5c181b031..53d2c8892 --- a/bin/tools/generate_authors.php +++ b/bin/tools/generate_authors.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php \d+)\s*(?P.*\w)\s*<(?P[^\s]+)>$/'; $contributors = array_map(function ($contributor) use ($regex) { + $result = []; preg_match($regex, $contributor, $result); return $result; }, $contributors); // filter out bots $contributors = array_filter($contributors, function ($contributor) { - return strpos($contributor['name'], 'Jenkins') !== 0; + if (empty($contributor['name']) || empty($contributor['email'])) { + return false; + } + if (strpos($contributor['email'], 'bot') || strpos($contributor['name'], 'bot')) { + return false; + } + return true; }); // turn tuples into markdown diff --git a/bin/tools/generate_explore.php b/bin/tools/generate_explore.php old mode 100644 new mode 100755 index 3ad19cb81..766e82db7 --- a/bin/tools/generate_explore.php +++ b/bin/tools/generate_explore.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php * @copyright Bernhard Posselt 2016 */ +require_once __DIR__ . '/../../vendor/autoload.php'; +require_once __DIR__ . '/../../../../lib/base.php'; + +use FeedIo\FeedIo; +use Favicon\Favicon; +use OCA\News\AppInfo\Application; + +$generator = new ExploreGenerator(); +$generator->parse_argv($argv); +print(json_encode($generator->read(), JSON_PRETTY_PRINT)); +print("\n"); /** * This is used for generating a JSON config section for a feed by executing: * php -f generate_authors.php www.feed.com + * @deprecated Use ./occ news:generate-explore instead. */ +class ExploreGenerator +{ + /** + * Feed and favicon fetcher. + */ + protected $reader; + protected $favicon; -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); + /** + * Argument data + */ + protected $url; + protected $votes; - $location = $resource->getUrl(); - $content = $resource->getContent(); - $encoding = $resource->getEncoding(); + /** + * Set up class. + */ + public function __construct() + { + $app = new Application(); + $container = $app->getContainer(); - $parser = $reader->getParser($location, $content, $encoding); + $this->reader = $container->query(FeedIo::class); + $this->favicon = new Favicon(); + } - $feed = $parser->execute(); + /** + * Parse required arguments. + * @param array $argv Arguments to the script. + * @return void + */ + public function parse_argv($argv = []) + { + if (count($argv) < 2 || count($argv) > 3) + { + print('Usage: php -f generate_explore http://path.com/feed [vote_count]'); + print("\n"); + exit(1); + } - $favicon = new PicoFeed\Reader\Favicon($config); + $this->votes = (count($argv) === 3) ? $argv[2] : 100; + $this->url = $argv[1]; + } - $result = [ - "title" => $feed->getTitle(), - "favicon" => $favicon->find($url), - "url" => $feed->getSiteUrl(), - "feed" => $feed->getFeedUrl(), - "description" => $feed->getDescription(), - "votes" => $votes - ]; + /** + * Read the provided feed and return the important data. + * @return array Object representation of the feed + */ + public function read() + { + try { + $resource = $this->reader->read($this->url); + $feed = $resource->getFeed(); + $result = [ + 'title' => $feed->getTitle(), + 'favicon' => $this->favicon->get($feed->getLink()), + 'url' => $feed->getLink(), + 'feed' => $this->url, + 'description' => $feed->getDescription(), + 'votes' => $this->votes, + ]; - if ($feed->getLogo()) { - $result["image"] = $feed->getLogo(); - } + return $result; + } catch (\Throwable $ex) { + return [ 'error' => $ex->getMessage() ]; + } + } - 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