summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorSean Molenaar <SMillerDev@users.noreply.github.com>2019-03-06 13:10:37 +0100
committerBenjamin Brahmer <info@b-brahmer.de>2019-03-06 13:10:37 +0100
commit71ba5a3ad1a1c9d867af68e72a4a19acd9ffe08d (patch)
treedebd3e30226df8def9e8f0bb30136c91db84184f /bin
parent6a4e56e7274d85bcbd0e2dcde7a61d8f7a4397ec (diff)
Fix generation commands and make them available in ./occ (#402)
Diffstat (limited to 'bin')
-rwxr-xr-x[-rw-r--r--]bin/tools/generate_authors.php10
-rwxr-xr-x[-rw-r--r--]bin/tools/generate_explore.php114
2 files changed, 82 insertions, 42 deletions
diff --git a/bin/tools/generate_authors.php b/bin/tools/generate_authors.php
index 5c181b031..53d2c8892 100644..100755
--- a/bin/tools/generate_authors.php
+++ b/bin/tools/generate_authors.php
@@ -1,3 +1,4 @@
+#!/usr/bin/env php
<?php
/**
* Nextcloud - News
@@ -15,13 +16,20 @@ exec($cmd, $contributors);
// extract data from git output into an array
$regex = '/^\s*(?P<commit_count>\d+)\s*(?P<name>.*\w)\s*<(?P<email>[^\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
index 3ad19cb81..766e82db7 100644..100755
--- a/bin/tools/generate_explore.php
+++ b/bin/tools/generate_explore.php
@@ -1,3 +1,4 @@
+#!/usr/bin/env php
<?php
/**
* Nextcloud - News
@@ -8,58 +9,89 @@
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @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