google_news
Unofficial Ruby gem to get Google News RSS feeds easily from Ruby or the command line.
Inspired by google-news-js.
[!WARNING]
Early alpha release. Use with caution.TODOs:
- CLI
- Support at all
- Support for different output formats (json, text, ...)
- More tests
- More documentation
Contents
Common information
This is just a simple RSS feed parser for Google News RSS feeds.
Can also be used from the command line!
There is support for:
- Top stories
- News by topic
- News by location
- News by keyword
- News by source
- News by language
Installation
Ruby
Add this line to your application's Gemfile:
gem 'google_news'
And then execute:
bundle install
Command line
If you just want to use the command line then run
gem install google_news
Usage
require 'google_news'
results = GoogleNews.headlines n: 5 # get top 5 news in default language (country: us, language: en)
puts results
# => [{"title"=>"Title of the news article", "link"=>"https://link.to/the/article", "pubDate"=>"Wed, 01 Jan 2024 00:00:00 GMT", "source"=>"Source Name"}, ...]
Command line
google_news
is also available on the command line after installation.
The results are printed in JSON format by default.
$ google_news --help
Usage: google_news [options]
-n, --number NUMBER Number of news articles to fetch (default: 10)
-c, --country COUNTRY Country code (default: 'us')
-l, --language LANGUAGE Language code (default: 'en')
-t, --topic TOPIC News topic (e.g., 'world', 'business', 'technology', etc.)
-s, --source SOURCE News source (e.g., 'bbc-news', 'cnn', etc.)
-k, --keyword KEYWORD Keyword to search for in news articles
-f, --format FORMAT Output format: 'json' (default) or 'text'
-h, --help Show this help message
Examples
Fetch top 5 news articles in the default language (country: us, language: en):
$ google_news -n 5
Documentation
Detailed (code) documentation is available at https://www.rubydoc.info/gems/google_news.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/magynhard/google_news. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.