Allow tweet.py to parse Twitter status URLs for replies

This commit is contained in:
Klaus-Uwe Mitterer 2016-09-13 20:20:05 +02:00
parent e0fe42a35d
commit a2b6d3d2e0
1 changed files with 14 additions and 2 deletions

View File

@ -4,10 +4,12 @@ import argparse, twitools
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Send a tweet from the status monitor\'s account.')
parser.add_argument('-r', '--reply', default=None, metavar='ID', type=int, help='reply to tweet ID')
parser.add_argument('-r', '--reply', default=None, metavar='ID', help='reply to tweet ID')
parser.add_argument('-t', '--text', default=None, type=str, help='tweet provided string')
args = parser.parse_args()
two = twitools.twObject()
try:
if not args.text:
text = input("> ")
@ -15,4 +17,14 @@ if __name__ == "__main__":
text = args.text
except KeyboardInterrupt:
exit(0)
two.tweet(text, args.reply)
if isinstance(args.reply, int):
reply = args.reply
else:
try:
if "twitter.com" in args.reply and "status" in args.reply:
reply = int(args.reply.split('/')[-1])
except:
raise ValueError("Invalid tweet ID passed for -r.")
two.tweet(text, reply)