Skip to content

Commit

Permalink
Fix code blocks in LMGTFY bot example
Browse files Browse the repository at this point in the history
(cherry picked from commit praw-dev/praw@4fa3b3b)
  • Loading branch information
LilSpazJoekp committed Nov 28, 2022
1 parent 3bb04b0 commit ee0177c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
3 changes: 1 addition & 2 deletions docs/examples/lmgtfy_bot.py
Expand Up @@ -40,5 +40,4 @@ async def process_submission(submission):


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
asyncio.run(main())
33 changes: 15 additions & 18 deletions docs/tutorials/reply_bot.rst
Expand Up @@ -185,24 +185,22 @@ some.
The first thing we should do is put all of our import statements at the top of the file.
It is common to list built-in packages before third-party ones:

.. include:: ../examples/lmgtfy_bot.py
:code: python
:end-line: 3
.. literalinclude:: ../examples/lmgtfy_bot.py
:language: python
:lines: -5

Next, we extract a few constants that are used in our script:

.. include:: ../examples/lmgtfy_bot.py
:code: python
:start-line: 4
:end-line: 6
.. literalinclude:: ../examples/lmgtfy_bot.py
:language: python
:lines: 7-8

We then extract the segment of code pertaining to processing a single submission into
its own function:

.. include:: ../examples/lmgtfy_bot.py
:code: python
:start-line: 18
:end-line: 33
.. literalinclude:: ../examples/lmgtfy_bot.py
:language: python
:pyobject: process_submission

Observe that we added some comments and a :py:func:`print` call. The :py:func:`print`
addition informs us every time we are about to reply to a submission, which is useful to
Expand All @@ -213,17 +211,16 @@ to turn your Python script into a Python module, i.e., import it from another Py
script or module. A common way to do that is to move the top-level code to a ``main``
function:

.. include:: ../examples/lmgtfy_bot.py
:code: python
:start-line: 8
:end-line: 16
.. literalinclude:: ../examples/lmgtfy_bot.py
:language: python
:pyobject: main

Finally, we need to call ``main`` only in the cases that this script is the one being
executed:

.. include:: ../examples/lmgtfy_bot.py
:code: python
:start-line: 35
.. literalinclude:: ../examples/lmgtfy_bot.py
:language: python
:lines: 42-

The Complete LMGTFY Bot
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit ee0177c

Please sign in to comment.