Replace Code Snippets page in documentation with Examples
authorHarmon <Harmon758@gmail.com>
Sat, 30 Oct 2021 17:23:57 +0000 (12:23 -0500)
committerHarmon <Harmon758@gmail.com>
Sat, 30 Oct 2021 17:23:57 +0000 (12:23 -0500)
docs/code_snippet.rst [deleted file]
docs/examples.rst [new file with mode: 0644]
docs/index.rst

diff --git a/docs/code_snippet.rst b/docs/code_snippet.rst
deleted file mode 100644 (file)
index bc57ab4..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-.. _code_snippet:
-
-
-*************
-Code Snippets
-*************
-
-Introduction
-============
-
-Here are some code snippets to help you out with using Tweepy. Feel
-free to contribute your own snippets or improve the ones here!
-
-OAuth
-=====
-
-.. code-block :: python
-
-   auth = tweepy.OAuthHandler("consumer_key", "consumer_secret")
-   
-   # Redirect user to Twitter to authorize
-   redirect_user(auth.get_authorization_url())
-   
-   # Get access token
-   auth.get_access_token("verifier_value")
-   
-   # Construct the API instance
-   api = tweepy.API(auth)
-
-FollowAll
-=========
-
-This snippet will follow every follower of the authenticated user.
-
-.. code-block :: python
-
-   for follower in tweepy.Cursor(api.followers).items():
-       follower.follow()
-
-Handling the rate limit using cursors
-=====================================
-   
-Since cursors raise ``RateLimitError``\ s while iterating,
-handling them can be done by wrapping the cursor in an iterator.
-   
-Running this snippet will print all users you follow that themselves follow
-less than 300 people total - to exclude obvious spambots, for example - and
-will wait for 15 minutes each time it hits the rate limit.
-   
-.. code-block :: python
-   
-   # In this example, the handler is time.sleep(15 * 60),
-   # but you can of course handle it in any way you want.
-   
-   def limit_handled(cursor):
-       while True:
-           try:
-               yield next(cursor)
-           except tweepy.RateLimitError:
-               time.sleep(15 * 60)
-   
-   for follower in limit_handled(tweepy.Cursor(api.followers).items()):
-       if follower.friends_count < 300:
-           print(follower.screen_name)
diff --git a/docs/examples.rst b/docs/examples.rst
new file mode 100644 (file)
index 0000000..5adefcc
--- /dev/null
@@ -0,0 +1,27 @@
+.. _examples:
+
+********
+Examples
+********
+
+.. tabs::
+
+   .. tab:: Authentication
+
+      .. literalinclude:: ../examples/authentication.py
+
+   .. tab:: PIN-based Authorization
+
+      .. literalinclude:: ../examples/pin-based_authorization.py
+
+   .. tab:: Tweet / Update Status
+
+      .. literalinclude:: ../examples/update_status.py
+
+   .. tab:: Follow Followers
+
+      .. literalinclude:: ../examples/follow_followers.py
+
+   .. tab:: Handle Rate Limits
+
+      .. literalinclude:: ../examples/rate_limit_handling.py
index 040ffe045f0c779514ab161d4c8b7f2231f552b4..baee10a799e2783c811e06fa937ca8dad75b62f9 100644 (file)
@@ -14,7 +14,6 @@ Contents:
    install.rst
    getting_started.rst
    auth_tutorial.rst
-   code_snippet.rst
    api.rst
    client.rst
    models.rst
@@ -26,6 +25,7 @@ Contents:
    streaming.rst
    running_tests.rst
    changelog.md
+   examples.rst
    faq.rst
 
 Indices and tables