CLI Usage
GNews includes a command-line interface available after pip install gnews.
Commands
search
gnews search "artificial intelligence"
gnews search "Pakistan" --lang ur --country PK --max 5
gnews search "OpenAI" --json
top
gnews top
gnews top --max 20 --json
topic
gnews topic TECHNOLOGY
gnews topic BUSINESS --max 10 --json
site
gnews site bbc.com
gnews site cnn.com --max 5 --json
location
gnews location Pakistan
gnews location "New York" --json
Common options
Option |
Default |
Description |
|---|---|---|
|
|
Language code |
|
|
Country code |
|
|
Max results |
|
off |
Output as JSON |
JSON output
The --json flag outputs valid JSON to stdout, making it easy to pipe into other tools:
gnews search "AI" --json | python3 -m json.tool
gnews top --json | jq '.[0].title'