# Usage: see pdt.sh example.
+""" for sys.argv """
import sys
import time
import tweepy
# 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':
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']}")