Skip to content

Commit d419ed7

Browse files
committed
Docs: Add requests example (Closes #45)
1 parent 5ca5513 commit d419ed7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/index.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ either as seconds or as `RFC 2326`_ Normal Play Time (NPT).
4242
Example
4343
=======
4444

45+
Using the built-in ``urllib.request`` module from Python 3:
46+
4547
.. code-block:: python
4648
4749
import podcastparser
@@ -57,6 +59,27 @@ Example
5759
5860
.. TODO: Show example dict for a parsed feed with all fields
5961
62+
63+
Using `Requests`_:
64+
65+
.. code-block:: python
66+
67+
import podcastparser
68+
import requests
69+
70+
url = 'https://example.net/podcast.atom'
71+
72+
with requests.get(url, stream=True) as response:
73+
response.raw.decode_content = True
74+
parsed = podcastparser.parse(url, response.raw)
75+
76+
# parsed is a dict
77+
import pprint
78+
pprint.pprint(parsed)
79+
80+
.. _Requests: https://requests.readthedocs.io
81+
82+
6083
Supported XML Elements and Attributes
6184
=====================================
6285

0 commit comments

Comments
 (0)