shahariaazam / news-aggregator
该包的最新版本(dev-development)没有可用的许可信息。
从各种来源汇总新闻。贡献您喜欢的新闻来源
dev-development
2020-05-22 22:25 UTC
Requires
- php: >= 7.2
- ext-json: *
- laminas/laminas-diactoros: ^2.2
- monolog/monolog: ^2.0
- pear/net_url2: ^2.2
- php-http/cache-plugin: ^1.7
- php-http/client-implementation: ^1.0
- php-http/curl-client: ^2.1
- php-http/discovery: ^1.0
- php-http/httplug: ^2.0
- php-http/logger-plugin: ^1.1
- php-http/message-factory: ^1.0
- php-http/stopwatch-plugin: ^1.3
- psr/cache: ^1.0
- psr/http-message: ^1.0
- psr/log: ^1.1
- symfony/cache: ^5.0
- symfony/console: ^5.0
- symfony/css-selector: ^5.0
- symfony/dom-crawler: ^5.0
Requires (Dev)
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-09-23 07:37:00 UTC
README
一个通用的 新闻聚合器,专为PHP开发者设计。一个简单、灵活且可扩展的库,用于以编程方式获取新闻标题和完整新闻文章。
目录
安装
使用Composer
要在您的应用程序中使用此库,您可以使用composer
进行安装。只需运行以下命令。
composer require shahariaazam/news-aggregator
就这样。
用法
从应用程序
您可以从支持的新闻提供商轻松获取新闻。以下是一个简单的代码片段,可以从特定的新闻提供商返回标题:
<?php use Shaharia\NewsAggregator\NewsProvider\BBC\BBC; use Shaharia\NewsAggregator\NewsProvider\BBC\HomepageParser; use Shaharia\NewsAggregator\Entity\Headline; require __DIR__ . "/vendor/autoload.php"; $aggregator = Shaharia\NewsAggregator\Aggregator::init(); /** * To get headlines we need to setup news provider and it's appropriate parser class * that will parse that provider's headlines. * * In this example, we are going to fetch all the headlines from BBC's homepage */ $headlines = $aggregator->getHeadlines( BBC::class, // BBC News provider class HomepageParser::class // BBC Homepage news parser class ); var_dump($headlines); // it will return Headline[] entity object
您可以在此处找到所有支持的新闻提供商及其相关的解析器类。
命令行
您还可以从命令行获取特定来源的新闻。以下是一个简单的命令,用于从BBC主页读取所有标题。
./bin/news headlines --list bbc-home
注意:bbc-home
是提供商的别名。您可以在此处找到所有支持的新闻提供商及其相关的提供商类。
所有支持的命令、参数和选项的列表在此。
如何扩展它?
/** * Customize your aggregator engine with your own libraries. * This library complies with dependency inversion principle. * * Attach your own PSR-7 compatible HTTP client * Attach your request factory, stream factory * Enable Cache with PSR-6 compatible caching library * Logger with PSR-3 compatible Logging client. */ $aggregator = Shaharia\NewsAggregator\Aggregator::init(); $aggregator->setHttpClient($client); $aggregator->setRequestFactory($requestFactory); $aggregator->setStreamFactory($streamFactory); $aggregator->setCache($cache); $aggregator->setLogger($logger);
Docker镜像
您还可以从您的最喜欢的来源获取新闻,或从Docker容器中读取新闻。要运行您的Docker容器,请编写以下命令:
docker run -it --rm shaharia/news-aggregator news headlines --list {NEWS_PROVIDER_SOURCE_SLUG} --json --with-url
CLI命令
以下是一些命令行参数
- ./bin/news headlines --help
Usage:
headlines [options]
Options:
-s, --source=SOURCE Source of the news
-u, --with-url With news URL
-j, --json Output in JSON format
- ./bin/news sources --help
Usage:
sources [options]
Options:
-l, --list List of available news sources
-s, --show=SHOW Show details about specific news source
可用的新闻来源
BBC
主页
- 提供商别名:
bbc-home
- URL:https://www.bbc.com/news
- 提供商类:
Shaharia\NewsAggregator\NewsProvider\BBC\BBC
- 解析器类:
Shaharia\NewsAggregator\NewsProvider\BBC\HomepageParser
- 支持的格式:
标题
每日Prothom Alo
主页
- URL:https://www.prothomalo.com/
- 提供商类:
Shaharia\NewsAggregator\NewsProvider\ProthomAlo\ProthomAlo
- 解析器类:
Shaharia\NewsAggregator\NewsProvider\ProthomAlo\ParserList
- 支持的格式:
标题
问题 & 缺陷报告
请从此处创建一个新的问题。
贡献
全球有许多新闻提供商。我无法为所有这些创建解析器。但请不要担心,您非常欢迎贡献。
您可以通过以下方式做出贡献:
- 添加新的新闻提供商(无解析器)
- 添加新的解析器
- 参与GitHub社区的Issue、讨论等。
- 创建新的问题、缺陷报告
- 修复现有的问题/缺陷
- 帮助他人
贡献者列表
您可以在此处查看完整的贡献者列表。