summaryrefslogtreecommitdiffstats
path: root/lib/Command
diff options
context:
space:
mode:
authorSean Molenaar <SMillerDev@users.noreply.github.com>2019-03-17 08:23:37 +0100
committerBenjamin Brahmer <info@b-brahmer.de>2019-03-17 08:23:37 +0100
commit2698214c4122d4f5f63f26f7a204035fe0d4f211 (patch)
treee1a033654736cc68f698af7110e8e17fdb0c2e55 /lib/Command
parentf5e25d2edef3360ed7fcdc1ecc663cfb37b650b7 (diff)
fix/allow CDATA encoding (#428)
Diffstat (limited to 'lib/Command')
-rw-r--r--lib/Command/ShowFeed.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/Command/ShowFeed.php b/lib/Command/ShowFeed.php
new file mode 100644
index 000000000..bbe1913fa
--- /dev/null
+++ b/lib/Command/ShowFeed.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Nextcloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Sean Molenaar <sean@seanmolenaar.eu>
+ * @copyright Sean Molenaar 2019
+ */
+namespace OCA\News\Command;
+
+use FeedIo\FeedIo;
+use Favicon\Favicon;
+
+use OCA\News\Fetcher\Fetcher;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * This is used for debugging feed data:
+ * ./occ news:show-feed www.feed.com
+ */
+class ShowFeed extends Command
+{
+ /**
+ * Feed and favicon fetcher.
+ */
+ protected $feedFetcher;
+
+ /**
+ * Set up class.
+ *
+ * @param Fetcher $feedFetcher Feed reader
+ */
+ public function __construct(Fetcher $feedFetcher)
+ {
+ $this->feedFetcher = $feedFetcher;
+ parent::__construct();
+ }
+
+ protected function configure()
+ {
+ $this->setName('news:show-feed')
+ ->setDescription('Prints a JSON string which represents the given feed as it would be in the DB.')
+ ->addArgument('feed', InputArgument::REQUIRED, 'Feed to parse')
+ ->addOption('user', 'u', InputOption::VALUE_OPTIONAL, 'Username for the feed')
+ ->addOption('password', 'p', InputOption::VALUE_OPTIONAL, 'Password for the feed');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $url = $input->getArgument('feed');
+ $user = $input->getOption('user');
+ $password = $input->getOption('password');
+
+ try {
+ list($feed, $items) = $this->feedFetcher->fetch($url, true, null, $user, $password);
+ $output->writeln("Feed: " . json_encode($feed, JSON_PRETTY_PRINT));
+ $output->writeln("Items: " . json_encode($items, JSON_PRETTY_PRINT));
+ } catch (\Throwable $ex) {
+ $output->writeln('<error>Failed to fetch feed info:</error>');
+ $output->writeln($ex->getMessage());
+ return 1;
+ }
+ }
+}