Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbinf committed Apr 27, 2021
0 parents commit c076c85
Show file tree
Hide file tree
Showing 18 changed files with 919 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[paths]
source =
listennotes
*/site-packages

[run]
branch = true
parallel = true
source = listennotes
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [flake8]
# exclude =
# setup.py

# E501 is the "Line too long" error. We disable it because we use Black for
# code formatting. Black makes a best effort to keep lines under the max
# length, but can go over in some cases.
# W503 goes against PEP8 rules. It's disabled by default, but must be disabled
# explicitly when using `ignore`.
# ignore = E501, W503
131 changes: 131 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

.idea/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Listen Notes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
VENV_NAME?=venv
PIP?=pip3
PYTHON?=python3

venv: $(VENV_NAME)/bin/activate

$(VENV_NAME)/bin/activate: setup.py
$(PIP) install --upgrade pip virtualenv
@test -d $(VENV_NAME) || $(PYTHON) -m virtualenv --clear $(VENV_NAME)
${VENV_NAME}/bin/python -m pip install -U pip tox
${VENV_NAME}/bin/python -m pip install -e .
@touch $(VENV_NAME)/bin/activate

test: venv
@${VENV_NAME}/bin/tox -p auto $(TOX_ARGS)

test-nomock: venv
@${VENV_NAME}/bin/tox -p auto -- --nomock $(TOX_ARGS)

test-travis: venv
${VENV_NAME}/bin/python -m pip install -U tox-travis
@${VENV_NAME}/bin/tox -p auto $(TOX_ARGS)

fmt: venv
@${VENV_NAME}/bin/tox -e fmt

fmtcheck: venv
@${VENV_NAME}/bin/tox -e fmt -- --check --verbose

lint: venv
@${VENV_NAME}/bin/tox -e lint

publish-test: test
${VENV_NAME}/bin/python -m pip install --upgrade twine
${VENV_NAME}/bin/python -m twine upload --repository testpypi .tox/dist/*

publish: test
${VENV_NAME}/bin/python -m pip install --upgrade twine
${VENV_NAME}/bin/python -m twine upload --repository pypi .tox/dist/*

clean:
@rm -rf $(VENV_NAME) .coverage .coverage.* build/ dist/ htmlcov/ *.egg-info .tox

.PHONY: venv test test-nomock test-travis coveralls fmt fmtcheck lint clean
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Podcast API Python Library

[![Build Status](https://travis-ci.com/ListenNotes/python-api-python.svg?branch=master)](https://travis-ci.com/ListenNotes/python-api-python)

The Podcast API Python library provides convenient access to the [Listen Notes Podcast API](https://www.listennotes.com/api/) from
applications written in the Python language.

Simple and no-nonsense podcast search & directory API. Search the meta data of all podcasts and episodes by people, places, or topics.

<a href="https://www.listennotes.com/api/"><img src="https://raw.githubusercontent.com/ListenNotes/ListenApiDemo/master/web/src/powered_by_listennotes.png" width="300" /></a>

## Documentation

See the [Listen Notes Podcast API docs](https://www.listennotes.com/api/docs/).


## Installation

You don't need this source code unless you want to modify the package. If you just
want to use the package, please run:

```sh
pip install --upgrade podcast-api
```

Install from source with:

```sh
make && source venv/bin/activate
```

### Requirements

- Python 3.5+

## Usage

The library needs to be configured with your account's API key which is
available in your [Listen API Dashboard](https://www.listennotes.com/api/dashboard/#apps). Set `api_key` to its
value:

```python
from listennotes import podcast_api

api_key = 'a6a1f7ae6a4a4cf7a208e5ba********'

client = podcast_api.Client(api_key=api_key)

response = client.search(q='star wars')

print(response.json())
```

If `api_key` is None, then we'll connect to a [mock server](https://www.listennotes.com/api/tutorials/#faq0) that returns fake data for testing purposes.

You can see all available API endpoints and parameters on the API Docs page at [listennotes.com/api/docs/](https://www.listennotes.com/api/docs/).

### Handling exceptions

Unsuccessful requests raise exceptions. The class of the exception will reflect
the sort of error that occurred.

All exception classes can be found in [this file](https://github.com/ListenNotes/podcast-api-python/blob/main/listennotes/errors.py).

And you can see some sample code [here](https://github.com/ListenNotes/podcast-api-python/blob/main/examples/sample.py#L17).
101 changes: 101 additions & 0 deletions examples/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import json
import os

from listennotes import podcast_api, errors

# Get your api key here: https://www.listennotes.com/api/dashboard/
api_key = os.environ.get("LISTEN_API_KEY", None)

client = podcast_api.Client(api_key=api_key)

#
# Boilerplate to make an api call
#
try:
response = client.typeahead(q="startup", show_podcasts=1)
print(json.dumps(response.json(), indent=2))
except errors.APIConnectionError:
print("Failed ot connect to Listen API servers")
except errors.AuthenticationError:
print("Wrong api key, or your account has been suspended!")
except errors.InvalidRequestError:
print("Wrong parameters!")
except errors.NotFoundError:
print("Endpoint not exist or the podcast / episode not exist!")
except errors.RateLimitError:
print("You have reached your quota limit!")
except errors.ListenApiError:
print("Something wrong on Listen Notes servers")
except Exception:
print("Other errors that may not be related to Listen API")
else:
headers = response.headers
print("\n=== Some account info ===")
print(
"Free Quota this month: %s requests"
% headers.get("X-ListenAPI-FreeQuota")
)
print("Usage this month: %s requests" % headers.get("X-ListenAPI-Usage"))
print("Next billing date: %s" % headers.get("X-Listenapi-NextBillingDate"))

# response = client.search(q='startup')
# print(response.json())

# response = client.fetch_best_podcasts()
# print(response.json())

# response = client.fetch_best_podcasts()
# print(response.json())

# response = client.fetch_podcast_by_id(id='4d3fe717742d4963a85562e9f84d8c79')
# print(response.json())

# response = client.fetch_episode_by_id(id='6b6d65930c5a4f71b254465871fed370')
# print(response.json())

# response = client.batch_fetch_episodes(ids='c577d55b2b2b483c969fae3ceb58e362,0f34a9099579490993eec9e8c8cebb82')
# print(response.json())

# response = client.batch_fetch_podcasts(ids='3302bc71139541baa46ecb27dbf6071a,68faf62be97149c280ebcc25178aa731,'
# '37589a3e121e40debe4cef3d9638932a,9cf19c590ff0484d97b18b329fed0c6a')
# print(response.json())

# response = client.fetch_curated_podcasts_list_by_id(id='SDFKduyJ47r')
# print(response.json())

# response = client.fetch_curated_podcasts_lists(page=2)
# print(response.json())

# response = client.fetch_curated_podcasts_lists(page=2)
# print(response.json())

# response = client.fetch_podcast_genres(top_level_only=0)
# print(response.json())

# response = client.fetch_podcast_regions()
# print(response.json())

# response = client.fetch_podcast_languages()
# print(response.json())

# response = client.just_listen()
# print(response.json())

# response = client.fetch_recommendations_for_podcast(id='25212ac3c53240a880dd5032e547047b', safe_mode=1)
# print(response.json())

# response = client.fetch_recommendations_for_episode(id='914a9deafa5340eeaa2859c77f275799', safe_mode=1)
# print(response.json())

# response = client.fetch_playlist_by_id(id='m1pe7z60bsw', type='podcast_list')
# print(response.json())

# response = client.fetch_my_playlists()
# print(response.json())

# response = client.submit_podcast(rss='https://feeds.megaphone.fm/committed')
# print(response.json())

# response = client.delete_podcast(
# id='4d3fe717742d4963a85562e9f84d8c79', reason='the podcaster wants to delete it')
# print(response.json())
Empty file added listennotes/__init__
Empty file.
Loading

0 comments on commit c076c85

Please sign in to comment.