Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code blocks in LMGTFY bot example #215

Merged
merged 1 commit into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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