You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provided under [MIT License](https://github.com/mattlisiv/newsapi-python/blob/master/LICENSE.txt) by Matt Lisivick.
13
+
14
+
```
15
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
11
17
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12
18
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13
19
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
```
15
22
16
-
## General
17
-
18
-
This is a Python client library for News API V2. The functions for the library should mirror the
19
-
endpoints from the [documentation](https://newsapi.org/docs/endpoints).
23
+
## General
20
24
25
+
This is a Python client library for [News API V2](https://newsapi.org/).
26
+
The functions and methods for this library should mirror the
27
+
endpoints specified by the News API [documentation](https://newsapi.org/docs/endpoints).
21
28
22
29
## Installation
23
-
Installation for the package can be done via pip.
24
30
25
-
```commandline
26
-
pip install newsapi-python
31
+
Installation for the package can be done via `pip`:
32
+
33
+
```bash
34
+
$ python -m pip install newsapi-python
27
35
```
28
36
29
37
## Usage
30
38
31
-
After installation, import client into your project:
39
+
After installation, import the client class into your project:
32
40
33
41
```python
34
42
from newsapi import NewsApiClient
@@ -41,19 +49,29 @@ api = NewsApiClient(api_key='XXXXXXXXXXXXXXXXXXXXXXX')
41
49
```
42
50
43
51
### Endpoints
44
-
52
+
53
+
An instance of `NewsApiClient` has three instance methods corresponding to three News API endpoints.
54
+
45
55
#### Top Headlines
46
56
57
+
Use `.get_top_headlines()` to pull from the [`/top-headlines`](https://newsapi.org/docs/endpoints/top-headlines) endpoint:
58
+
47
59
```python
48
60
api.get_top_headlines(sources='bbc-news')
49
61
```
62
+
50
63
#### Everything
51
64
65
+
Use `.get_everything()` to pull from the [`/everything`](https://newsapi.org/docs/endpoints/everything) endpoint:
66
+
52
67
```python
53
68
api.get_everything(q='bitcoin')
54
69
```
70
+
55
71
#### Sources
56
72
73
+
Use `.get_sources()` to pull from the [`/sources`](https://newsapi.org/docs/endpoints/sources) endpoint:
74
+
57
75
```python
58
76
api.get_sources()
59
77
```
@@ -64,7 +82,10 @@ You will encounter an error if you attempt to print the .json() object to the co
64
82
This becomes especially annoying if developers wish to get 'under the hood'.
65
83
66
84
Here is the error:
67
-
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 1444: character maps to <undefined>
85
+
86
+
```
87
+
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 1444: character maps to <undefined>
88
+
```
68
89
69
90
This can be fixed by:
70
91
- installing 'win-unicode-console'
@@ -73,7 +94,7 @@ This can be fixed by:
73
94
`py -mrun myPythonScript.py`
74
95
75
96
Another option is hardcoding your console to only print in utf-8. This is a bad idea, as it could ruin many other scripts and/or make errors MUCH more difficult to track.
0 commit comments