在这个数字时代,有大量的应用程序和实用程序可用于在线阅读新闻。 其中大多数是基于 GUI 的。 幸运的是,有一个命令行实用程序可以为那些整天住在终端的人阅读新闻。 见面 “即时新闻” – 一个简单但有用的 CLI 实用程序,用于从命令行获取新闻。 该实用程序可立即检索各种新闻并将其显示在终端中。 因此,您不需要任何 GUI 应用程序,也不需要离开终端,甚至不需要硬拷贝来阅读世界新闻。 在这个简短的教程中,我将解释如何安装“instantnews”以及如何在类 Unix 操作系统中从终端获取世界新闻。
安装 即时新闻
Instantnews 实用程序可以使用以下任一方式安装 点子 或者可以直接从源代码编译安装。
使用画中画:
一、安装 点子 如下所示。
在 Arch Linux 及其衍生版本上,运行以下命令来安装 pip:
$ sudo pacman -S python-pip
在 Debian、Ubuntu、Linux Mint 上:
$ sudo apt-get install python-pip
在 RHEL 上, Fedora中央操作系统:
$ sudo yum install python-pip
或者,
$ sudo dnf install python-pip
在 SUSE/openSUSE 上:
$ sudo zypper install python-pip
安装 pip 后,使用 pip 命令安装 Instantnews:
$ pip install instantnews
从源安装:
要从源代码构建,请执行以下操作:
$ git clone https://github.com/shivam043/instantnews.git $ cd instantnew $ sudo python setup.py install
配置即时新闻
Instantnews 检索所有新闻标题 新闻 API. 对于那些想知道的人,News API 是一个简单易用的 API,它返回当前发布在一系列新闻源和博客上的标题的 JSON 元数据。 它目前提供来自 70 个热门来源的实时头条新闻,包括 Ars Technica、BBC、Blooberg、CNN、每日邮报、Engadget、ESPN、金融时报、谷歌新闻、黑客新闻、IGN、Mashable、国家地理、Reddit r/all、路透社、 Speigel Online、Techcrunch、卫报、印度教、赫芬顿邮报、纽约时报、下一个网络、华尔街日报、今日美国和 更多的.
首先,您需要来自 News API 的 API 密钥。 去 https://newsapi.org/register URL 并注册一个免费帐户以获取 API 密钥。
从 News API 站点获得 API 密钥后,编辑您的 .bashrc 文件:
$ vi ~/.bashrc
在末尾添加 newsapi API 密钥,如下所示:
export IN_API_KEY="Paste-API-key-here"
请注意,您需要将密钥粘贴在双引号内。 Save 和 close 文件。
运行以下命令以更新更改。
$ source ~/.bashrc
在 Linux 中使用 Instantnews 从命令行即时获取新闻
要显示帮助,请运行:
$ instantnews -h usage: instantnews [-h] [--show SHOW] [--show_all] [--news NEWS] optional arguments: -h, --help show this help message and exit --show SHOW, -s SHOW Shows all the news channel codes category wise --show_all, -sa Shows all the news channel codes --news NEWS, -n NEWS Shows news
列出所有可用的新闻频道
让我们看看所有可用新闻频道的列表。
$ instantnews -sa
或者,
$ instantnews --show_all
示例输出为:
News Code: <abc-news-au> ABC News (AU) News Code: <al-jazeera-english> Al Jazeera English News Code: <ars-technica> Ars Technica News Code: <associated-press> Associated Press News Code: <bbc-news> BBC News News Code: <bbc-sport> BBC Sport News Code: <bild> Bild News Code: <bloomberg> Bloomberg News Code: <breitbart-news> Breitbart News News Code: <business-insider> Business Insider News Code: <business-insider-uk> Business Insider (UK) News Code: <buzzfeed> Buzzfeed News Code: <cnbc> CNBC News Code: <cnn> CNN News Code: <daily-mail> Daily Mail News Code: <der-tagesspiegel> Der Tagesspiegel News Code: <die-zeit> Die Zeit News Code: <engadget> Engadget News Code: <entertainment-weekly> Entertainment Weekly News Code: <espn> ESPN News Code: <espn-cric-info> ESPN Cric Info News Code: <financial-times> Financial Times News Code: <focus> Focus News Code: <football-italia> Football Italia News Code: <fortune> Fortune News Code: <four-four-two> FourFourTwo News Code: <fox-sports> Fox Sports News Code: <google-news> Google News News Code: <gruenderszene> Gruenderszene News Code: <hacker-news> Hacker News News Code: <handelsblatt> Handelsblatt News Code: <ign> IGN News Code: <independent> Independent News Code: <mashable> Mashable News Code: <metro> Metro News Code: <mirror> Mirror News Code: <mtv-news> MTV News News Code: <mtv-news-uk> MTV News (UK) News Code: <national-geographic> National Geographic News Code: <new-scientist> New Scientist News Code: <newsweek> Newsweek News Code: <new-york-magazine> New York Magazine News Code: <nfl-news> NFL News News Code: <polygon> Polygon News Code: <recode> Recode News Code: <reddit-r-all> Reddit /r/all News Code: <reuters> Reuters News Code: <spiegel-online> Spiegel Online News Code: <t3n> T3n News Code: <talksport> TalkSport News Code: <techcrunch> TechCrunch News Code: <techradar> TechRadar News Code: <the-economist> The Economist News Code: <the-guardian-au> The Guardian (AU) News Code: <the-guardian-uk> The Guardian (UK) News Code: <the-hindu> The Hindu News Code: <the-huffington-post> The Huffington Post News Code: <the-lad-bible> The Lad Bible News Code: <the-new-york-times> The New York Times News Code: <the-next-web> The Next Web News Code: <the-sport-bible> The Sport Bible News Code: <the-telegraph> The Telegraph News Code: <the-times-of-india> The Times of India News Code: <the-verge> The Verge News Code: <the-wall-street-journal> The Wall Street Journal News Code: <the-washington-post> The Washington Post News Code: <time> Time News Code: <usa-today> USA Today News Code: <wired-de> Wired.de News Code: <wirtschafts-woche> Wirtschafts Woche
就像我已经提到的那样,在撰写本指南时有 70 个新闻来源。 在未来的日子里会增加更多。 正如您在上面的输出中看到的,所有新闻代码都列在一个输出中。 您还可以明智地显示新闻频道类别。
明智地列出新闻频道类别
要明智地显示所有新闻频道代码类别,请运行:
$ instantnews --show SHOW <category>
或者,
$ instantnews -s SHOW <category>
以下类别可用。
- 商业
- 娱乐
- 游戏
- 一般的
- 音乐
- 政治
- 科学与自然
- 运动
- 技术
现在,要明智地显示新闻频道类别,比如技术,请运行:
$ instantnews --show technology
或者,
$ instantnews -s technology
示例输出为:
News Code: <ars-technica> Ars Technica News Code: <engadget> Engadget News Code: <gruenderszene> Gruenderszene News Code: <hacker-news> Hacker News News Code: <recode> Recode News Code: <t3n> T3n News Code: <techcrunch> TechCrunch News Code: <techradar> TechRadar News Code: <the-next-web> The Next Web News Code: <the-verge> The Verge News Code: <wired-de> Wired.de
立即从终端获取新闻
要从新闻频道获取新闻头条,请说 印度教,使用正确的新闻代码运行以下命令:
$ instantnews --news the-hindu
或者,
$ instantnews -n the-hindu
现在,您将看到来自给定新闻来源的所有新闻头条,即我们案例中的印度教徒。
即时新闻在行动
同样,您可以阅读任何其他来源的新闻。 为了 example,要阅读来自 Techcrunch 的新闻头条,请运行以下命令:
$ instantnews -n techcrunch
建议阅读:
- Clinews – 从命令行阅读新闻和最新标题
在测试它时,我注意到我无法在我的网络浏览器中打开任何特定的新闻代码来阅读更多关于它的信息。 我想这是一个错误。 当然,没有没有错误的代码。 希望开发者修复它并添加一些新功能。 这个项目非常新,正在积极开发中。 如果有任何错误或功能请求,请在最后给出的 GitHub 页面中通知他们。
资源:
感谢您的光临!
帮助我们帮助您:
- 订阅我们的电子邮件通讯: 立即注册
- 支持 OSTechNix: 通过贝宝捐款
- 下载免费的电子书和视频: TradePub 上的 OSTechNix
- 联系我们: 红迪网 | Facebook | Twitter | 领英 | RSS订阅
祝你有美好的一天!!