Skip to content

Commit c076c85

Browse files
committed
Initial commit
0 parents  commit c076c85

18 files changed

+919
-0
lines changed

.coveragerc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[paths]
2+
source =
3+
listennotes
4+
*/site-packages
5+
6+
[run]
7+
branch = true
8+
parallel = true
9+
source = listennotes

.flake8

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# [flake8]
2+
# exclude =
3+
# setup.py
4+
5+
# E501 is the "Line too long" error. We disable it because we use Black for
6+
# code formatting. Black makes a best effort to keep lines under the max
7+
# length, but can go over in some cases.
8+
# W503 goes against PEP8 rules. It's disabled by default, but must be disabled
9+
# explicitly when using `ignore`.
10+
# ignore = E501, W503

.gitignore

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
.idea/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Listen Notes
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.

Makefile

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
VENV_NAME?=venv
2+
PIP?=pip3
3+
PYTHON?=python3
4+
5+
venv: $(VENV_NAME)/bin/activate
6+
7+
$(VENV_NAME)/bin/activate: setup.py
8+
$(PIP) install --upgrade pip virtualenv
9+
@test -d $(VENV_NAME) || $(PYTHON) -m virtualenv --clear $(VENV_NAME)
10+
${VENV_NAME}/bin/python -m pip install -U pip tox
11+
${VENV_NAME}/bin/python -m pip install -e .
12+
@touch $(VENV_NAME)/bin/activate
13+
14+
test: venv
15+
@${VENV_NAME}/bin/tox -p auto $(TOX_ARGS)
16+
17+
test-nomock: venv
18+
@${VENV_NAME}/bin/tox -p auto -- --nomock $(TOX_ARGS)
19+
20+
test-travis: venv
21+
${VENV_NAME}/bin/python -m pip install -U tox-travis
22+
@${VENV_NAME}/bin/tox -p auto $(TOX_ARGS)
23+
24+
fmt: venv
25+
@${VENV_NAME}/bin/tox -e fmt
26+
27+
fmtcheck: venv
28+
@${VENV_NAME}/bin/tox -e fmt -- --check --verbose
29+
30+
lint: venv
31+
@${VENV_NAME}/bin/tox -e lint
32+
33+
publish-test: test
34+
${VENV_NAME}/bin/python -m pip install --upgrade twine
35+
${VENV_NAME}/bin/python -m twine upload --repository testpypi .tox/dist/*
36+
37+
publish: test
38+
${VENV_NAME}/bin/python -m pip install --upgrade twine
39+
${VENV_NAME}/bin/python -m twine upload --repository pypi .tox/dist/*
40+
41+
clean:
42+
@rm -rf $(VENV_NAME) .coverage .coverage.* build/ dist/ htmlcov/ *.egg-info .tox
43+
44+
.PHONY: venv test test-nomock test-travis coveralls fmt fmtcheck lint clean

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Podcast API Python Library
2+
3+
[![Build Status](https://travis-ci.com/ListenNotes/python-api-python.svg?branch=master)](https://travis-ci.com/ListenNotes/python-api-python)
4+
5+
The Podcast API Python library provides convenient access to the [Listen Notes Podcast API](https://www.listennotes.com/api/) from
6+
applications written in the Python language.
7+
8+
Simple and no-nonsense podcast search & directory API. Search the meta data of all podcasts and episodes by people, places, or topics.
9+
10+
<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>
11+
12+
## Documentation
13+
14+
See the [Listen Notes Podcast API docs](https://www.listennotes.com/api/docs/).
15+
16+
17+
## Installation
18+
19+
You don't need this source code unless you want to modify the package. If you just
20+
want to use the package, please run:
21+
22+
```sh
23+
pip install --upgrade podcast-api
24+
```
25+
26+
Install from source with:
27+
28+
```sh
29+
make && source venv/bin/activate
30+
```
31+
32+
### Requirements
33+
34+
- Python 3.5+
35+
36+
## Usage
37+
38+
The library needs to be configured with your account's API key which is
39+
available in your [Listen API Dashboard](https://www.listennotes.com/api/dashboard/#apps). Set `api_key` to its
40+
value:
41+
42+
```python
43+
from listennotes import podcast_api
44+
45+
api_key = 'a6a1f7ae6a4a4cf7a208e5ba********'
46+
47+
client = podcast_api.Client(api_key=api_key)
48+
49+
response = client.search(q='star wars')
50+
51+
print(response.json())
52+
```
53+
54+
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.
55+
56+
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/).
57+
58+
### Handling exceptions
59+
60+
Unsuccessful requests raise exceptions. The class of the exception will reflect
61+
the sort of error that occurred.
62+
63+
All exception classes can be found in [this file](https://github.com/ListenNotes/podcast-api-python/blob/main/listennotes/errors.py).
64+
65+
And you can see some sample code [here](https://github.com/ListenNotes/podcast-api-python/blob/main/examples/sample.py#L17).

examples/sample.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import json
2+
import os
3+
4+
from listennotes import podcast_api, errors
5+
6+
# Get your api key here: https://www.listennotes.com/api/dashboard/
7+
api_key = os.environ.get("LISTEN_API_KEY", None)
8+
9+
client = podcast_api.Client(api_key=api_key)
10+
11+
#
12+
# Boilerplate to make an api call
13+
#
14+
try:
15+
response = client.typeahead(q="startup", show_podcasts=1)
16+
print(json.dumps(response.json(), indent=2))
17+
except errors.APIConnectionError:
18+
print("Failed ot connect to Listen API servers")
19+
except errors.AuthenticationError:
20+
print("Wrong api key, or your account has been suspended!")
21+
except errors.InvalidRequestError:
22+
print("Wrong parameters!")
23+
except errors.NotFoundError:
24+
print("Endpoint not exist or the podcast / episode not exist!")
25+
except errors.RateLimitError:
26+
print("You have reached your quota limit!")
27+
except errors.ListenApiError:
28+
print("Something wrong on Listen Notes servers")
29+
except Exception:
30+
print("Other errors that may not be related to Listen API")
31+
else:
32+
headers = response.headers
33+
print("\n=== Some account info ===")
34+
print(
35+
"Free Quota this month: %s requests"
36+
% headers.get("X-ListenAPI-FreeQuota")
37+
)
38+
print("Usage this month: %s requests" % headers.get("X-ListenAPI-Usage"))
39+
print("Next billing date: %s" % headers.get("X-Listenapi-NextBillingDate"))
40+
41+
# response = client.search(q='startup')
42+
# print(response.json())
43+
44+
# response = client.fetch_best_podcasts()
45+
# print(response.json())
46+
47+
# response = client.fetch_best_podcasts()
48+
# print(response.json())
49+
50+
# response = client.fetch_podcast_by_id(id='4d3fe717742d4963a85562e9f84d8c79')
51+
# print(response.json())
52+
53+
# response = client.fetch_episode_by_id(id='6b6d65930c5a4f71b254465871fed370')
54+
# print(response.json())
55+
56+
# response = client.batch_fetch_episodes(ids='c577d55b2b2b483c969fae3ceb58e362,0f34a9099579490993eec9e8c8cebb82')
57+
# print(response.json())
58+
59+
# response = client.batch_fetch_podcasts(ids='3302bc71139541baa46ecb27dbf6071a,68faf62be97149c280ebcc25178aa731,'
60+
# '37589a3e121e40debe4cef3d9638932a,9cf19c590ff0484d97b18b329fed0c6a')
61+
# print(response.json())
62+
63+
# response = client.fetch_curated_podcasts_list_by_id(id='SDFKduyJ47r')
64+
# print(response.json())
65+
66+
# response = client.fetch_curated_podcasts_lists(page=2)
67+
# print(response.json())
68+
69+
# response = client.fetch_curated_podcasts_lists(page=2)
70+
# print(response.json())
71+
72+
# response = client.fetch_podcast_genres(top_level_only=0)
73+
# print(response.json())
74+
75+
# response = client.fetch_podcast_regions()
76+
# print(response.json())
77+
78+
# response = client.fetch_podcast_languages()
79+
# print(response.json())
80+
81+
# response = client.just_listen()
82+
# print(response.json())
83+
84+
# response = client.fetch_recommendations_for_podcast(id='25212ac3c53240a880dd5032e547047b', safe_mode=1)
85+
# print(response.json())
86+
87+
# response = client.fetch_recommendations_for_episode(id='914a9deafa5340eeaa2859c77f275799', safe_mode=1)
88+
# print(response.json())
89+
90+
# response = client.fetch_playlist_by_id(id='m1pe7z60bsw', type='podcast_list')
91+
# print(response.json())
92+
93+
# response = client.fetch_my_playlists()
94+
# print(response.json())
95+
96+
# response = client.submit_podcast(rss='https://feeds.megaphone.fm/committed')
97+
# print(response.json())
98+
99+
# response = client.delete_podcast(
100+
# id='4d3fe717742d4963a85562e9f84d8c79', reason='the podcaster wants to delete it')
101+
# print(response.json())

listennotes/__init__

Whitespace-only changes.

0 commit comments

Comments
 (0)