cleanup for pylint
authorIan Kelling <iank@fsf.org>
Wed, 22 Nov 2023 03:50:48 +0000 (22:50 -0500)
committerIan Kelling <iank@fsf.org>
Wed, 22 Nov 2023 03:50:48 +0000 (22:50 -0500)
t.py

diff --git a/t.py b/t.py
index bbe78605ff088351733605e7c11951bf08da0e0a..164553f21dada4712a4418fdbcd758345e7f0c19 100755 (executable)
--- a/t.py
+++ b/t.py
@@ -18,6 +18,7 @@
 
 # Usage: see pdt.sh example.
 
+""" for sys.argv """
 import sys
 import time
 import tweepy
@@ -27,20 +28,25 @@ from twitter_keys import *
 # import logging
 # logging.basicConfig(level=logging.DEBUG)
 
+
+## begin cli option parsing ##
+verbose = False
+if len(sys.argv) == 2 and sys.argv[1] == "-v":
+    verbose = True
+## end cli option parsing ##
+
+
+## Begin setup api ##
 auth = tweepy.OAuth1UserHandler(
     consumer_key, consumer_secret, access_token, access_token_secret
 )
-
 api = tweepy.API(auth)
-
 client = tweepy.Client(
     consumer_key=consumer_key, consumer_secret=consumer_secret,
     access_token=access_token, access_token_secret=access_token_secret
 )
-verbose = False
+## End setup api ##
 
-if len(sys.argv) == 2 and sys.argv[1] == "-v":
-    verbose = True
 
 if len(sys.argv) == 3:
     if sys.argv[1] == '--delete':
@@ -54,47 +60,50 @@ if len(sys.argv) == 3:
     else:
         print("t.py: error: unexpected argument. exiting without doing anything")
         sys.exit(1)
-else:
-    input_text = input()
+    sys.exit(0)
 
-    posts=input_text.split("/tnt/")
-    post_count=len(posts)
+#### For the rest of the script:: no action specified in cli arguments,
+#### post based on input from STDIN
 
-    tweet_text=posts[0].strip()
+input_text = input()
+posts=input_text.split("/tnt/")
+post_count=len(posts)
 
-    if post_count > 1:
-        tweet_text=tweet_text + f" 1/{post_count}"
+tweet_text=posts[0].strip()
 
-    have_image = True
-    try:
-        image_path = input()
-    except EOFError:
-        have_image = False
+if post_count > 1:
+    tweet_text=tweet_text + f" 1/{post_count}"
 
-    have_alt = True
-    try:
-        alt = input()
-    except EOFError:
-        have_alt = False
+have_image = True
+try:
+    image_path = input()
+except EOFError:
+    have_image = False
 
-    if have_image:
-        media = api.media_upload(image_path)
-        media_id = media.media_id_string
+have_alt = True
+try:
+    alt = input()
+except EOFError:
+    have_alt = False
 
-    if have_alt:
-        api.create_media_metadata(media_id, alt)
+if have_image:
+    media = api.media_upload(image_path)
+    media_id = media.media_id_string
 
+if have_alt:
+    api.create_media_metadata(media_id, alt)
 
-    if have_image:
-        response = client.create_tweet(text=tweet_text, media_ids=[media_id])
-    else:
-        response = client.create_tweet(text=tweet_text)
+
+if have_image:
+    response = client.create_tweet(text=tweet_text, media_ids=[media_id])
+else:
+    response = client.create_tweet(text=tweet_text)
+    if verbose:
+        print(f"https://nitter.net/user/status/{response.data['id']}")
+if post_count > 1:
+    for x in range(1, post_count):
+        time.sleep(1)
+        tweet_text=posts[x].strip() + f" {x+1}/{post_count}"
+        response = client.create_tweet(text=tweet_text, in_reply_to_tweet_id=response.data['id'])
         if verbose:
-            print(f"https://nitter.net/user/status/{response.data['id']}")
-    if post_count > 1:
-        for x in range(1, post_count):
-            time.sleep(1)
-            tweet_text=posts[x].strip() + f" {x+1}/{post_count}"
-            response = client.create_tweet(text=tweet_text, in_reply_to_tweet_id=response.data['id'])
-            if verbose:
-                print(f"{x+1}/{post_count} https://nitter.net/USER/status/{response.data['id']}")
+            print(f"{x+1}/{post_count} https://nitter.net/USER/status/{response.data['id']}")