Skip to content

Commit bb28dd2

Browse files
Merge pull request #13 from SubhrajitPrusty/master
added cli for gnewsclient, updated README with instructions
2 parents fabf6c2 + 444b7b2 commit bb28dd2

File tree

7 files changed

+113
-3
lines changed

7 files changed

+113
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/dist/
33
/*.egg
44
/*.egg-info
5+
venv

CLI.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# gnews
2+
3+
CLI to use gnewsclient
4+
5+
How to use?
6+
-----------
7+
8+
To use, it is recommended to make `virtualenv` and then install all required packages:
9+
10+
* Installing virtualenv:
11+
```
12+
$ sudo pip install virtualenv
13+
```
14+
* Making virtualenv:
15+
```
16+
$ virtualenv venv
17+
```
18+
* Go to your gnewsclient dir and activate it:
19+
```
20+
$ . venv/bin/activate
21+
```
22+
* To install all required packages:
23+
```
24+
$ pip install --editable .
25+
or
26+
$ sudo pip install --editable .
27+
```
28+
29+
30+
## Usage: `$ gnews [OPTIONS]`
31+
32+
```
33+
Options:
34+
--config shows default config
35+
--query TEXT shows news about query given
36+
--edition TEXT shows news of edition given, default=United States
37+
(English)
38+
--topic TEXT shows topic given, default=top stories
39+
--location TEXT shows news from location given
40+
--language TEXT shows news in language given, default is english
41+
--sheditions shows list of available editions
42+
--shtopics shows list of available topics
43+
--shlangs shows list of available languages
44+
--help Show this message and exit.
45+
46+
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ To install gnewsclient, simply,
1414
$ pip install gnewsclient
1515
```
1616

17+
To install and use **gnewsclient CLI**, follow instructions here [CLI](CLI.md)
18+
1719
## Filters
1820

1921
Google News feeds use 3 basic filters:

gnewsclient/gnewsclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_config(self):
4141
'edition': self.edition,
4242
'topic': self.topic,
4343
'language': self.language,
44-
'loaction': self.location,
44+
'location': self.location,
4545
'query': self.query
4646
}
4747
return config

gnewsclient/scripts/__init__.py

Whitespace-only changes.

gnewsclient/scripts/gnews.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import click
2+
from gnewsclient import gnewsclient
3+
4+
client = gnewsclient()
5+
6+
@click.command()
7+
@click.option("--config",is_flag=True,help="shows default config")
8+
9+
@click.option("--query",default=None,help="shows news about query given")
10+
@click.option("--edition",default="United States (English)",help="shows news of edition given, default=United States (English)")
11+
@click.option("--topic",default="top stories",help="shows topic given, default=top stories")
12+
@click.option("--location",default=None,help="shows news from location given")
13+
@click.option("--language",default="english",help="shows news in language given, default is english")
14+
15+
@click.option("--sheditions",is_flag=True,help="shows list of available editions")
16+
@click.option("--shtopics",is_flag=True,help="shows list of available topics")
17+
@click.option("--shlangs",is_flag=True,help="shows list of available languages")
18+
19+
def cli(config,query,edition,topic,location,language,shlangs,shtopics,sheditions):
20+
""" CLI to get news """
21+
22+
client.query = query
23+
client.edition = edition
24+
client.topic = topic
25+
client.location = location
26+
client.language = language
27+
28+
if config:
29+
conf = client.get_config()
30+
click.echo("The default configuration : ")
31+
for keys,value in conf.items():
32+
click.echo(str(keys)+" : "+str(value))
33+
34+
elif shlangs:
35+
langs = client.languages
36+
click.echo("The languages supported : ")
37+
for l in langs:
38+
click.echo(l)
39+
40+
elif sheditions:
41+
editions = client.editions
42+
click.echo("The editions available : ")
43+
for e in editions:
44+
click.echo(e)
45+
46+
elif shtopics:
47+
tps = client.topics
48+
click.echo("The topics available : ")
49+
for t in tps:
50+
click.echo(t)
51+
else:
52+
neews = client.get_news()
53+
for n in neews:
54+
content = "{}\n{}".format(n['title'],n['link'])
55+
click.echo(content)
56+
click.echo("\n")

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def readme():
3131
author_email = '[email protected]',
3232
license = 'MIT',
3333
packages = ['gnewsclient'],
34-
install_requires = ['requests', 'bs4', 'html5lib'],
34+
install_requires = ['requests', 'bs4', 'html5lib', 'Click'],
3535
include_package_data = True,
36-
zip_safe = False)
36+
zip_safe = False,
37+
entry_points='''
38+
[console_scripts]
39+
gnews=gnewsclient.scripts.gnews:cli
40+
''',
41+
)

0 commit comments

Comments
 (0)