Skip to content

Commit 4f63718

Browse files
author
mlisivick
committed
Initial Commit
0 parents  commit 4f63718

9 files changed

Lines changed: 158 additions & 0 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea
2+
*.pyc
3+
build/
4+
dist/
5+
*.egg-info/
6+
*.rst
7+
venv/
8+
*log.txt

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Matt Lisivick
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# gdax-python
2+
A Python client for the [News API](https://newsapi.org/docs/)
3+
4+
##### Provided under MIT License by Matt Lisivick.
5+
*Note: this library may be subtly broken or buggy. The code is released under
6+
the MIT License – please take the following message to heart:*
7+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
9+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
10+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
11+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
12+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

newsapi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from newsapi.newsapi_client import NewsApiClient

newsapi/newsapi_auth.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from requests.auth import AuthBase
2+
3+
4+
class NewsApiAuth(AuthBase):
5+
# Provided by newsapi: https://newsapi.org/docs/authentication
6+
def __init__(self, api_key):
7+
self.api_key = api_key
8+
9+
def __call__(self, request):
10+
request.headers.update(get_auth_headers(self.api_key))
11+
return request
12+
13+
14+
def get_auth_headers(api_key):
15+
return {
16+
'Content-Type': 'Application/JSON',
17+
'Authorization': api_key
18+
}

newsapi/newsapi_client.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import requests
2+
from newsapi.newsapi_auth import NewsApiAuth
3+
4+
5+
class NewsApiClient(object):
6+
7+
def __init__(self, api_key, api_url='https://newsapi.org/v2/'):
8+
self.url = api_url.rstrip('/')
9+
self.auth = NewsApiAuth(api_key=api_key)
10+
11+
def get_top_headlines(self, q=None, sources=None, language=None, country=None):
12+
# Define Payload
13+
payload = {}
14+
payload['q'] = q
15+
payload['sources'] = sources
16+
payload['language'] = language
17+
payload['country'] = country
18+
19+
# Send Request
20+
r = requests.get(self.url + '/top-headlines', auth=self.auth, timeout=30, params=payload)
21+
return r.json()
22+
23+
def get_everything(self, q=None, sources=None, domains=None, from_parameter=None, to=None, language=None, sort_by=None,
24+
page=None):
25+
# Define Payload
26+
payload = {}
27+
payload['q'] = q
28+
payload['sources'] = sources
29+
payload['domains'] = domains
30+
payload['from'] = from_parameter
31+
payload['to'] = to
32+
payload['language'] = language
33+
payload['sortBy'] = sort_by
34+
payload['page'] = page
35+
36+
# Send Request
37+
r = requests.get(self.url + '/everything', auth=self.auth, timeout=30, params=payload)
38+
return r.json()
39+
40+
def get_sources(self, category=None, language=None, country=None):
41+
# Define Payload
42+
payload = {}
43+
payload['category'] = category
44+
payload['language'] = language
45+
payload['country'] = country
46+
47+
# Send Request
48+
r = requests.get(self.url + '/sources', auth=self.auth, timeout=30, params=payload)
49+
return r.json()
50+
51+
52+

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[metadata]
2+
description-file = README.md
3+
4+
[bdist_wheel]
5+
universal=1

setup.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
from setuptools import setup, find_packages
4+
5+
install_requires = [
6+
'requests==2.13.0'
7+
]
8+
9+
tests_require = [
10+
'pytest',
11+
]
12+
13+
setup(
14+
name='newsapi-python',
15+
version='0.0.1',
16+
author='Matt Lisivick',
17+
author_email='lisivickmatt@gmail.com',
18+
license='MIT',
19+
url='https://github.com/mattlisiv/newsapi-python',
20+
packages=find_packages(),
21+
install_requires=install_requires,
22+
tests_require=tests_require,
23+
description='An unofficial Python client for the News API',
24+
download_url='https://github.com/mattlisiv/newsapi-python/archive/master.zip',
25+
keywords=['newsapi','news'],
26+
classifiers=[
27+
'Development Status :: 5 - Production/Stable',
28+
'Intended Audience :: Developers',
29+
'Intended Audience :: Financial and Insurance Industry',
30+
'Intended Audience :: Information Technology',
31+
'Topic :: Software Development :: Libraries :: Python Modules',
32+
'License :: OSI Approved :: MIT License',
33+
'Programming Language :: Python :: 2',
34+
'Programming Language :: Python :: 2.6',
35+
'Programming Language :: Python :: 2.7',
36+
'Programming Language :: Python :: 3',
37+
'Programming Language :: Python :: 3.3',
38+
'Programming Language :: Python :: 3.4',
39+
'Programming Language :: Python :: 3.5',
40+
],
41+
)

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)