Welcome to kcrw.apple_news’s documentation!¶
kcrw.apple_news
is a simple library for using the Apple News API from Python 2 or 3 (>= 2.7 or >= 3.5).
- Free software: MIT license
- Documentation: https://kcrwapple-news.readthedocs.io.
Features¶
- Provides support for making signed API requests to the Apple News Publisher API
- Includes suport for “Read Channel”, “Create Article”, “Update Article”, “Read Article Information”, “Delete Article” API calls as well making generic signed requests.
- Provides a command line tool
apple_news_api
for making API calls directly.
Installation¶
Stable release¶
To install kcrw.apple_news, run this command in your terminal:
$ pip install kcrw.apple_news
This is the preferred method to install kcrw.apple_news, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for kcrw.apple_news can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/KCRW-org/kcrw.apple_news
Or download the tarball:
$ curl -OL https://github.com/KCRW-org/kcrw.apple_news/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Usage¶
To use kcrw.apple_news in a project:
from kcrw.apple_news import API
api = API('MY_KEY', 'MY_SECRET', 'MY_CHANNEL_ID')
channel_data = api.channel()
new_article = api.create_article(article_data, metadata, {'asset1.jpg: ...})
updated_article = api.update_article(
'ARTICLE_ID', metadata, article_data, {'updated_asset.jpg': ...}
)
article = api.read('ARTICLE_ID')
api.delete('ARTICLE_ID')
You can also use the included command line tool:
$ apple_news_api channel $ apple_news_api create path/to/folder $ apple_news_api updated ARTICLE_ID path/to_folder $ apple_news_api read ARTICLE_ID $ apple_news_api delete ARTICLE_ID
kcrw.apple_news classes¶
Library for making Apple News API requests
-
class
kcrw.apple_news.api.
API
(key_id, key_secret, channel_id)[source]¶ Apple News API object
-
__init__
(key_id, key_secret, channel_id)[source]¶ Parameters: - key_id (str) – Apple News API Key Id
- key_secret (str) – Apple News API Secret
- channel_id (str) – Apple News Channel Id
-
channel_id
= None¶
-
create_article
(article, metadata=None, assets=None)[source]¶ Creates and uploads a multi-part article. See Create an Article
article
andmetadata
should contain JSON-serializable dictionaries according the API specification for article data and optional article creation metadata.assets
should contain a dict mapping of filenames to file data for all supplemental assets needed for the article.Parameters: - article (dict -- or None) – Article data in JSON serializable python dict
- metadata – Optional metadata in JSON serializable python dict
- assets (dict -- or None) – Dict with filename -> data mapping of additional assets
Returns: dict – the JSON data returned by the API.
Raises: AppleNewsException
-
delete_article
(identifier)[source]¶ Deletes an existing a article. See Delete an Article.
Requires an
identifier
for an existing article.Parameters: identifier (str) – An identifier for an existing Apple News article Returns: dict – the JSON data returned by the API. Raises: AppleNewsException
-
key_id
= None¶
-
key_secret
= None¶
-
read_article
(identifier)[source]¶ Retrieves information about an existing a article. See Read Article Information.
Requires an
identifier
for an existing article.Parameters: identifier (str) – An identifier for an existing Apple News article Returns: dict – the JSON data returned by the API. Raises: AppleNewsException
-
read_channel
()[source]¶ Read basic information about the current Apple News Channel
Returns: dict – the JSON data returned by the API. Raises: AppleNewsException
-
send_request
(method, route, body=None, content_type=None)[source]¶ Sends a signed request to the Apple News Publisher API.
Parameters: - method (str) – The HTTP method for the request (e.g. GET, POST, …)
- route (str) – The API route for the request
- body (str) – The request body
- content_type (str) – The request content type
Returns: dict – the JSON data returned by the API.
Raises: AppleNewsException
-
update_article
(identifier, metadata, article=None, assets=None)[source]¶ Updates an existing a article. See Update an Article.
Requires an
identifier
for an existing article, and metadata containing the current articlerevision
identifier. All other arguments are optional.Parameters: - identifier (str) – An identifier for an existing Apple News article
- metadata (dict) – JSON formatted article metadata
- article (dict -- or None) – Article data in JSON serializable python dict
- assets (dict -- or None) – Dict with filename -> data mapping of additional assets
Returns: dict – the JSON data returned by the API.
Raises: AppleNewsException
-
url_base
= 'https://news-api.apple.com'¶
-
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/KCRW-org/kcrw.apple_news/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
Write Documentation¶
kcrw.apple_news could always use more documentation, whether as part of the official kcrw.apple_news docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/KCRW-org/kcrw.apple_news/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up kcrw.apple_news for local development.
Fork the kcrw.apple_news repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/kcrw.apple_news.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv kcrw.apple_news $ cd kcrw.apple_news/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 kcrw.apple_news tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
If you have specified
cookiecutter.use_pytest == 'y'
run the tests with:$ python setup.py pytest
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
Deploying¶
A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:
$ bump2version patch # possible: major / minor / patch
$ git push
$ git push --tags
Credits¶
Development Lead¶
- Alec Mitchell <alecpm@gmail.com>
Acknowledgments¶
Development sponsored in part by KCRW radio in Santa Monica, CA. Help fund local public radio by donating at https://join.kcrw.com.
The code in this package is largely inspired by the Apple News API Tutorial.
This package relies heavily on requests and click and was generated using the Cookiecutter namespace-template template.
History¶
0.2.6 (2020-04-17)¶
- Fix namespace package issues
0.2.4 (2020-03-09)¶
- Fix namespace package issues
0.2.3 (2020-02-27)¶
- Fixes to support applications that pin six < 1.12.0
0.2.2 (2020-02-26)¶
- Include response error codes and data in custom exception.
0.2.1 (2020-02-25)¶
- Fix bumpversion error
0.2.0 (2020-02-25)¶
- Fix botched package release
0.1.0 (2020-02-24)¶
- First release on PyPI