Modular scripts to take text, images, and links from RSS feeds and push to social media
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
agaetr/tweet.patch

126 lines
3.3 KiB

--- tweet-full.py 2018-07-22 12:12:09.000000000 -0400
+++ tweet.py 2018-07-22 14:42:40.946489274 -0400
@@ -5,91 +5,49 @@
from __future__ import division
##
-# Copyright (C) Benjamin D. McGinnes, 2013-2017
-# ben@adversary.org
-# OpenPGP/GPG key: 0x321E4E2373590E5D
-#
-# Version: 0.0.1
-#
-# BTC: 1KvKMVnyYgLxU1HnLQmbWaMpDx3Dz15DVU
-#
-#
+# Originally derived from a script by Benjamin D. McGinnes, licensed
+# under the Apache 2.0 license
#
# Requirements:
#
# * Python 3.4 or later.
-# * Converted from scripts initially developed with Python 2.7.x.
-#
-# Options and notes:
-#
# Usage:
-#
+# tweet.py --message "Thing to tweet" --file /path/to/file/to/tweet
##
-from license import __author__
-from license import __copyright__
-from license import __copyrighta__
-from license import __license__
-__version__ = "0.0.1"
-from license import __bitcoin__
-
-# import datetime
-# import time
import os
import os.path
import sys
+import argparse
from twython import Twython, TwythonError
-from config import *
+
+APP_KEY = ""
+APP_SECRET = ""
+OAUTH_TOKEN = ""
+OAUTH_TOKEN_SECRET = ""
+
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
cred = twitter.verify_credentials()
l = len(sys.argv)
-print("""
-Enter the message, filenames of any images to upload and the status ID
-of a tweet if you are replying to it.
-
-Media filenames need to include either full or relative paths. Up to
-4 images (GIF, JPG or PNG), or 1 animated GIF, or 1 short video (MP4).
-
-If replying to a Tweet then the status ID of the tweet must be entered
-at the relevant prompt. It can accept the URL of the tweet if the
-status ID numbe is the last part of the URL. The username of the
-person being replied to, including the at symbol must be included in
-any reply, otherwise it is merely another tweet.
-
-Will always prompt for the reply status ID and the media filenames,
-but the tweet can be entered with the command like with tweet-basic.py
-or at a prompt. The latter method is recommended when used with some
-non-ASCII characters, but the former may be more conducive to
-combining with foad.py and similar types of scripts.
-""")
-
-
-reply_id = input("If replying to someone, enter the status ID of that message: ")
-media_fn = input("If uploading images, enter the filename(s),separated by spaces (max. 4): ")
-
-
-if l >= 2:
- msg = []
- for i in range(l - 1):
- msg.append(str(sys.argv[i + 1]))
- message = " ".join(msg)
-else:
- message = input("Enter your Tweet: ")
+parser = argparse.ArgumentParser(add_help=False)
+parser.add_argument('-f', '--file', action='store',dest='media_fn', nargs='+')
+parser.add_argument('-t', '--tweet', action='store',dest='message', nargs='+')
+args = parser.parse_args()
-if len(reply_id) > 0:
- twid0 = reply_id.split("/")
- twid1 = twid0[-1]
- try:
- twid = int(twid1)
- except:
- twid = None
-else:
- twid = None
+print ('Media file is ', args.media_fn)
+print ('Message is ', args.message)
+
+reply_id = None
+twid = None
-if len(media_fn) > 0:
+message = args.message
+media_fn = args.media_fn
+
+
+if media_fn is not None:
mfiles = media_fn.split()
lm = len(mfiles)
mfid = []
@@ -110,7 +68,6 @@
else:
mfid = None
-
if len(message) < 1 and twid is None and mfid is None:
mesg = None
elif len(message) < 1 and twid is None and mfid is not None: