mirror of https://github.com/uriel1998/agaetr
parent
d0660ebf75
commit
0f4cc2718c
@ -0,0 +1,258 @@ |
||||
#!/bin/bash |
||||
|
||||
######################################################################## |
||||
# Init |
||||
######################################################################## |
||||
|
||||
initialize () { |
||||
COMPOSING=0 |
||||
SENSITIVE=0 |
||||
CONTENTWARNING="" |
||||
|
||||
if [ -f "$HOME/.config/rss_social.rc" ];then |
||||
readarray -t line < "$HOME/.config/rss_social.rc" |
||||
TOOTCLI=${line[0]} |
||||
TWEETCLI=${line[1]} |
||||
FBCLI=${line[2]} |
||||
GPLUSCLI=${line[3]} |
||||
RSSFEEDS=${line[4]} |
||||
CACHEDIR=${line[5]} |
||||
SENDNUM=${line[6]} |
||||
ENCODER=${line[7]} |
||||
else |
||||
echo "Configuration file not set up properly." |
||||
exit |
||||
fi |
||||
|
||||
if [ ! -d "$CACHEDIR" ];then |
||||
mkdir -p "$CACHEDIR" |
||||
if [ ! -f "$CACHEFILE" ];then |
||||
echo "" > "$CACHEFILE" |
||||
fi |
||||
fi |
||||
|
||||
CACHEFILE=$(echo "$CACHEDIR/urls") |
||||
if [ ! -f "$CACHEFILE" ];then |
||||
echo "" > "$CACHEFILE" |
||||
fi |
||||
|
||||
TEMPDIR="$CACHEDIR/tempfiles" |
||||
if [ ! -d "$TEMPDIR" ];then |
||||
mkdir -p "$TEMPDIR" |
||||
fi |
||||
|
||||
TEMPRSS=$(echo "$TEMPDIR/temprss.txt") |
||||
echo "" > "$TEMPRSS" |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
######################################################################## |
||||
# Expand all shortened urls |
||||
######################################################################## |
||||
expand() { |
||||
resulturl="" |
||||
resulturl=$(wget -O- --server-response $testurl 2>&1 | grep "^Location" | tail -1 | awk -F ' ' '{print $2}') |
||||
if [ -z "$resulturl" ]; then |
||||
resulturl=$(echo "$testurl") |
||||
fi |
||||
} |
||||
|
||||
######################################################################## |
||||
# Get the image from the RSS feed |
||||
######################################################################## |
||||
|
||||
getimg() { |
||||
read |
||||
wget -qO "$TEMPIMG" "$url" |
||||
if [ "$?" -gt 0 ];then |
||||
#error getting image |
||||
TEMPIMG="" |
||||
fi |
||||
} |
||||
|
||||
######################################################################## |
||||
# Post each item to respective services |
||||
######################################################################## |
||||
postit() { |
||||
if grep -Fxq "$PERMLINK" "$CACHEFILE" |
||||
then |
||||
#echo "ERROR: $PERMLINK" |
||||
echo "§ Already sent: $PERMLINK" |
||||
else |
||||
echo "§ Setting up posting for $PERMLINK" |
||||
echo "$PERMLINK" >> "$CACHEFILE" |
||||
# Remember sensitive and CW. CW is a string |
||||
|
||||
#Caching the result and image |
||||
bob=$(date +"%Y%m%d%H%M%s") |
||||
|
||||
ThisPostDir="$CACHEDIR/$bob" |
||||
mkdir "$ThisPostDir" |
||||
ToEncodeString=$(echo "$ENCODER $PERMLINK") |
||||
# EncodedUrl=$(eval "$ToEncodeString") |
||||
EncodedUrl=$($ENCODER "$PERMLINK") |
||||
|
||||
if [ -z "$TEMPIMG" ];then |
||||
# post without image |
||||
poststring=$(echo "$TITLE $PERMLINK") |
||||
tweetstring=$(printf "--message \"%s %s\"" "$TITLE" "$PERMLINK") |
||||
if [ ! -z "$CONTENTWARNING"];then |
||||
tootstring=$(printf "post --spoiler-text \"%s\" \"%s %s\"" "$CONTENTWARNING" "$TITLE" "$PERMLINK") |
||||
else |
||||
tootstring=$(printf "post \"%s %s\"" "$TITLE" "$PERMLINK") |
||||
fi |
||||
#not sure if -remote will work with pexpect |
||||
fbstring=$(printf "-auto-submit https://www.facebook.com/sharer/sharer.php?u=%s" "$EncodedUrl") |
||||
gplusstring=$(printf "-auto-submit https://plus.google.com/share?url=%s" "$EncodedUrl") |
||||
else |
||||
# post with image |
||||
|
||||
imgname=$(basename "$TEMPIMG") |
||||
cpstring="$TEMPIMG $ThisPostDir" |
||||
out=$(eval cp "$cpstring") |
||||
#rewriting the variable so I don't have to find it later. |
||||
TEMPIMG2=$(echo "$ThisPostDir/$imgname") |
||||
poststring=$(echo "$TITLE $PERMLINK $TEMPIMG") |
||||
tweetstring=$(printf " --message \"%s %s\" --file %s" "$TITLE" "$PERMLINK" "$TEMPIMG2") |
||||
if [ ! -z "$CONTENTWARNING" ];then |
||||
tootstring=$(printf "post --spoiler-text \"%s\" \"%s %s\" --media %s" "$CONTENTWARNING" "$TITLE" "$PERMLINK" "$TEMPIMG2") |
||||
else |
||||
tootstring=$(printf "post \"%s %s\" --media %s" "$TITLE" "$PERMLINK" "$TEMPIMG2") |
||||
fi |
||||
if [ "$SENSITIVE" -gt 0 ];then |
||||
tootstring=$(printf "%s --sensitive" "$tootstring") |
||||
fi |
||||
fbstring=$(printf " -auto-submit https://www.facebook.com/sharer/sharer.php?u=%s" "$EncodedUrl") |
||||
gplusstring=$(printf " -auto-submit https://plus.google.com/share?url=%s" "$EncodedUrl") |
||||
fi |
||||
# echo "WOULD POST::" |
||||
# echo "$tweetstring" |
||||
# echo "$tootstring" |
||||
# echo "$fbstring" |
||||
# echo "$gplusstring" |
||||
|
||||
ThisPostText=$(echo "$ThisPostDir/posting.txt") |
||||
touch "$ThisPostText" |
||||
if [ "$TOOTCLI" != "FALSE" ];then |
||||
echo "$tootstring" >> "$ThisPostText" |
||||
fi |
||||
if [ "$TWEETCLI" != "FALSE" ];then |
||||
echo "$tweetstring" >> "$ThisPostText" |
||||
fi |
||||
if [ "$FBCLI" != "FALSE" ];then |
||||
echo "$fbstring" >> "$ThisPostText" |
||||
fi |
||||
if [ "$GPLUSCLI" != "FALSE" ];then |
||||
echo "$gplusstring" >> "$ThisPostText" |
||||
fi |
||||
# Little bit of cleaning up here... |
||||
if [ -f "$TEMPIMG" ];then |
||||
rm "$TEMPIMG" |
||||
fi |
||||
sleep 2 #to make sure our dirnames are different |
||||
read |
||||
fi |
||||
} |
||||
|
||||
######################################################################## |
||||
# Parse feeds here |
||||
######################################################################## |
||||
parse_feeds (){ |
||||
while read -r line; do |
||||
case $line in |
||||
title* ) |
||||
TITLE=$(echo "$line" | awk -F 'title=' '{print $2}' | awk -F 'http' '{print $1}') |
||||
#strip url off title if it is there |
||||
COMPOSING=1 |
||||
;; |
||||
link/@href* ) |
||||
testurl=$(echo "$line" | awk -F 'link/@href=' '{print $2}') |
||||
expand |
||||
#strip off any _utm things and/or stupid :large things on the end |
||||
url=$(echo "$resulturl" | awk -F '?utm_' '{print $1}' | awk -F ':' '{print $1":"$2 }') |
||||
case $url in |
||||
*jpg*) |
||||
TEMPIMG="$TEMPDIR/temp.jpg" |
||||
getimg |
||||
;; |
||||
*png*) |
||||
TEMPIMG="$TEMPDIR/temp.png" |
||||
getimg |
||||
;; |
||||
*gif*) |
||||
TEMPIMG="$TEMPDIR/temp.gif" |
||||
getimg |
||||
;; |
||||
*twitter*) |
||||
echo "store, maybe useful?" |
||||
;; |
||||
*) |
||||
PERMLINK="$url" |
||||
;; |
||||
esac |
||||
;; |
||||
source/link/@href*) |
||||
testurl=$(echo "$line" | awk -F 'link/@href=' '{print $2}') |
||||
expand |
||||
#strip off any _utm things and/or stupid :large things on the end |
||||
sourceurl=$(echo "$resulturl" | awk -F '?utm_' '{print $1}' | awk -F ':' '{print $1":"$2 }' | grep -v -e "atom" -e "rss" -e "xml") |
||||
#If there's something here and not the permalink (like if it's to a tweet?)... |
||||
if [ -z "$PERMLINK" ];then |
||||
PERMLINK="$sourceurl" |
||||
fi |
||||
;; |
||||
# content is not parsed for here because it's usually html and way too long |
||||
# I can release something later for that, I guess. |
||||
/feed/entry* ) |
||||
# If you're currently putting together something, you've hit the next entry |
||||
if [ $COMPOSING == 1 ];then |
||||
postit |
||||
COMPOSING=0 |
||||
fi |
||||
;; |
||||
link/@rel=enclosure*) |
||||
# This is probably the end of one.... (also triggers on the last entry) |
||||
if [ $COMPOSING == 1 ];then |
||||
postit |
||||
COMPOSING=0 |
||||
fi |
||||
;; |
||||
esac |
||||
done < "$TEMPRSS" |
||||
} |
||||
|
||||
######################################################################## |
||||
# Pull in feeds here |
||||
######################################################################## |
||||
pull_feeds () { |
||||
SENSITIVE=0 |
||||
CONTENTWARNING="" |
||||
|
||||
while read -r line; do |
||||
case $line in |
||||
@SEN*) SENSITIVE=1;; |
||||
# NEED TO CHECK HERE SO THAT IF SOMEONE LEAVES IT OFF... |
||||
@CON=*) CONTENTWARNING=$(echo "$line" | awk -F '@CON=' '{print $2}');; |
||||
http*) |
||||
curl -s --max-time 10 "$line" | xml2 | sed 's|/feed/entry/||' > "$TEMPRSS" |
||||
parse_feeds |
||||
rm "$TEMPRSS" |
||||
SENSITIVE=0 |
||||
CONTENTWARNING="" |
||||
;; |
||||
*) echo "ignoring commented line" ;; |
||||
esac |
||||
done < "$RSSFEEDS" |
||||
|
||||
} |
||||
|
||||
######################################################################## |
||||
# Main |
||||
######################################################################## |
||||
initialize |
||||
pull_feeds |
||||
|
||||
#Clean |
||||
rmdir "$TEMPDIR" |
@ -0,0 +1,8 @@ |
||||
/usr/bin/toot |
||||
$HOME/bin/tweet.py |
||||
/usr/bin/elinks |
||||
/usr/bin/elinks |
||||
$HOME/.config/rss_social_feeds.rc |
||||
$HOME/.cache/rss_social |
||||
1 |
||||
/path/to/urlencode.sh |
@ -0,0 +1,6 @@ |
||||
http://feeds.dlvr.it/7ff3a9f9def74078842acd7f0c7bd9a8.xml |
||||
@CON="Political" |
||||
http://feeds.dlvr.it/7ff3a9f9def74078842acd7f0c7bd9a8.xml |
||||
@SEN |
||||
@CON="NSFW" |
||||
http://feeds.dlvr.it/7ff3a9f9def74078842acd7f0c7bd9a8.xml |
@ -0,0 +1,68 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
'''This demonstrates an FTP "bookmark". This connects to an ftp site; does a |
||||
few ftp stuff; and then gives the user interactive control over the session. In |
||||
this case the "bookmark" is to a directory on the OpenBSD ftp server. It puts |
||||
you in the i386 packages directory. You can easily modify this for other sites. |
||||
|
||||
PEXPECT LICENSE |
||||
|
||||
This license is approved by the OSI and FSF as GPL-compatible. |
||||
http://opensource.org/licenses/isc-license.txt |
||||
|
||||
Copyright (c) 2012, Noah Spurrier <noah@noah.org> |
||||
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY |
||||
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE |
||||
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. |
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
||||
|
||||
''' |
||||
|
||||
from __future__ import absolute_import |
||||
from __future__ import print_function |
||||
from __future__ import unicode_literals |
||||
|
||||
import pexpect |
||||
import sys |
||||
import time |
||||
import datetime |
||||
|
||||
KEY_UP = '\x1b[A' |
||||
KEY_DOWN = '\x1b[B' |
||||
KEY_RIGHT = '\x1b[C' |
||||
KEY_LEFT = '\x1b[D' |
||||
KEY_ESCAPE = '\x1b' |
||||
KEY_BACKSPACE = '\x7f' |
||||
KEY_ENTER = '\x1b[13' |
||||
|
||||
# Note that, for Python 3 compatibility reasons, we are using spawnu and |
||||
# importing unicode_literals (above). spawnu accepts Unicode input and |
||||
# unicode_literals makes all string literals in this script Unicode by default. |
||||
child = pexpect.spawnu('elinks -auto-submit https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fideatrash.net') |
||||
|
||||
print ('waiting for python.org to load') |
||||
child.expect ('Warning') |
||||
time.sleep(0.1) |
||||
child.sendline(KEY_ENTER) # "the requested fragment doesn't exist ... but it did post." |
||||
print ('quitting') |
||||
child.sendline('q') |
||||
child.sendline(KEY_ENTER) |
||||
|
||||
|
||||
# The rest is not strictly necessary. This just demonstrates a few functions. |
||||
# This makes sure the child is dead; although it would be killed when Python exits. |
||||
if child.isalive(): |
||||
child.sendline('bye') # Try to ask ftp child to exit. |
||||
child.close() |
||||
# Print the final state of the child. Normally isalive() should be FALSE. |
||||
if child.isalive(): |
||||
print('Child did not exit gracefully.') |
||||
else: |
||||
print('Child exited gracefully.') |
||||
|
@ -0,0 +1,85 @@ |
||||
#!/bin/bash |
||||
|
||||
######################################################################## |
||||
# Init |
||||
######################################################################## |
||||
|
||||
initialize () { |
||||
TEMPFILE=$(mktemp) |
||||
TEMPDIR=$(mktemp -d) |
||||
|
||||
if [ -f "$HOME/.config/rss_social.rc" ];then |
||||
readarray -t line < "$HOME/.config/rss_social.rc" |
||||
TOOTCLI=${line[0]} |
||||
TWEETCLI=${line[1]} |
||||
FBCLI=${line[2]} |
||||
GPLUSCLI=${line[3]} |
||||
RSSFEEDS=${line[4]} |
||||
CACHEDIR=${line[5]} |
||||
SENDNUM=${line[6]} |
||||
ENCODER=${line[7]} |
||||
else |
||||
echo "Configuration file not set up properly." |
||||
exit |
||||
fi |
||||
|
||||
CACHEFILE=$(echo "$CACHEDIR/urls") |
||||
|
||||
} |
||||
|
||||
# for directories in cachedir |
||||
# get the posting.txt file (tempimg, if it exists, will be encoded) |
||||
# read the posting.txt file - first line is tweet second tood |
||||
# maybe use an array there? |
||||
# execute the programs |
||||
|
||||
NUMSENT=0 |
||||
|
||||
# Might have an option for sorted or random later, but for right now... |
||||
# Getting the cache dirs in numerical order (e.g. first in first out) |
||||
# The first line will actually be the base dir but won't have the |
||||
# appropriate file, so it'll skip |
||||
find "$CACHEDIR" -maxdepth 1 -type d -exec echo {} \; | sort > "$TEMPFILE" |
||||
|
||||
while read -r d; do |
||||
if [ -d "$d" ]; then |
||||
if [ -f "$d/posting.txt" ];then |
||||
readarray -t line < "$d/posting.txt" |
||||
ToToot=${line[0]} |
||||
ToTweet=${line[1]} |
||||
ToFB=${line[2]} |
||||
ToGPlus=${line[3]} |
||||
|
||||
if [ -z "$ToToot" ];then |
||||
SocialString=$(echo "$TOOTCLI $ToToot") |
||||
output=$(eval "$SocialString") |
||||
echo "$output" |
||||
fi |
||||
if [ -z "$ToTweet" ];then |
||||
SocialString=$(echo "$TWEETTCLI $ToTweet") |
||||
output=$(eval "$SocialString") |
||||
echo "$output" |
||||
fi |
||||
if [ -z "$ToFB" ];then |
||||
SocialString=$(echo "$FBCLI $ToFB") |
||||
output=$(eval "$SocialString") |
||||
echo "$output" |
||||
fi |
||||
((NUMSENT++)) |
||||
rm -rf "$d" |
||||
else |
||||
echo "Not a post file" |
||||
fi |
||||
|
||||
|
||||
if [ "$NUMSENT" -ge "$SENDNUM" ];then |
||||
exit |
||||
fi |
||||
fi |
||||
done < "$TEMPFILE" |
||||
} |
||||
|
||||
#Clean |
||||
|
||||
rm -rf "$TEMPDIR" |
||||
rm "$TEMPFILE" |
@ -0,0 +1,126 @@ |
||||
--- 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:
|
@ -0,0 +1,137 @@ |
||||
#!/usr/bin/env python3 |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
from __future__ import unicode_literals |
||||
from __future__ import division |
||||
|
||||
## |
||||
# Originally derived from a script by Benjamin D. McGinnes, licensed |
||||
# under the Apache 2.0 license |
||||
# |
||||
# Requirements: |
||||
# |
||||
# * Python 3.4 or later. |
||||
# Usage: |
||||
# tweet.py --message "Thing to tweet" --file /path/to/file/to/tweet |
||||
## |
||||
|
||||
import os |
||||
import os.path |
||||
import sys |
||||
import argparse |
||||
from twython import Twython, TwythonError |
||||
|
||||
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) |
||||
|
||||
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() |
||||
|
||||
print ('Media file is ', args.media_fn) |
||||
print ('Message is ', args.message) |
||||
|
||||
reply_id = None |
||||
twid = None |
||||
|
||||
message = args.message |
||||
media_fn = args.media_fn |
||||
|
||||
|
||||
if media_fn is not None: |
||||
mfiles = media_fn.split() |
||||
lm = len(mfiles) |
||||
mfid = [] |
||||
for i in range(lm): |
||||
if os.path.isfile(os.path.realpath(mfiles[i])) is True: |
||||
mediaf = os.path.realpath(mfiles[i]) |
||||
elif os.path.isfile(os.path.realpath("InputFiles/{0}".format(mfiles[i]))) is True: |
||||
mediaf = os.path.realpath("InputFiles/{0}".format(mfiles[i])) |
||||
else: |
||||
mediaf = None |
||||
|
||||
if mediaf is None: |
||||
mfid.append(mediaf) |
||||
else: |
||||
mf = open(mediaf, "rb") |
||||
response = twitter.upload_media(media=mf) |
||||
mfid.append(response["media_id"]) |
||||
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: |
||||
mesg = "." |
||||
elif len(message) < 1 and twid is not None and mfid is not None: |
||||
users = [] |
||||
hashtags = [] |
||||
try: |
||||
tweet = twitter.show_status(id=twid) |
||||
user1 = "@"+tweet["user"]["screen_name"] |
||||
users.append(user1) |
||||
rtweet = tweet["text"] |
||||
rtword = rtweet.split() |
||||
for i in range(len(rtword)): |
||||
if rtword[i].startswith("@") is True: |
||||
users.append(rtword[i]) |
||||
elif rtword[i].startswith("#") is True: |
||||
hashtags.append(rtword[i]) |
||||
else: |
||||
pass |
||||
ustr = " ".join(users) |
||||
hstr = " ".join(hashtags) |
||||
mesg = "{0} {1}".format(ustr, hstr) |
||||
except TwythonError as e: |
||||
print(e) |
||||
mesg = "." |
||||
else: |
||||
mesg = message |
||||
|
||||
|
||||
if mesg is not None and twid is None and mfid is None: |
||||
try: |
||||
twitter.update_status(status=mesg) |
||||
except TwythonError as e: |
||||
print(e) |
||||
elif mesg is not None and twid is not None and mfid is None: |
||||
try: |
||||
twitter.update_status(status=mesg, in_reply_to_status_id=twid) |
||||
except TwythonError as e: |
||||
print(e) |
||||
elif mesg is not None and twid is None and mfid is not None: |
||||
try: |
||||
twitter.update_status(status=mesg, media_ids=mfid) |
||||
except TwythonError as e: |
||||
print(e) |
||||
elif mesg is not None and twid is not None and mfid is not None: |
||||
try: |
||||
twitter.update_status(status=mesg, media_ids=mfid, |
||||
in_reply_to_status_id=twid) |
||||
except TwythonError as e: |
||||
print(e) |
||||
elif mesg is None and twid is None and mfid is not None: |
||||
try: |
||||
twitter.update_status(status="", media_ids=mfid) |
||||
except TwythonError as e: |
||||
print(e) |
||||
elif mesg is None and twid is not None and mfid is not None: |
||||
try: |
||||
twitter.update_status(status="", media_ids=mfid, |
||||
in_reply_to_status_id=twid) |
||||
except TwythonError as e: |
||||
print(e) |
||||
else: |
||||
print(""" |
||||
As with all things in this world, you get out of it what you put in |
||||
and you put in nothing. |
||||
""") |
@ -0,0 +1,21 @@ |
||||
#!/bin/bash |
||||
|
||||
######################################################################## |
||||
# Url Encode snippet from https://gist.github.com/cdown/1163649 |
||||
######################################################################## |
||||
|
||||
urlencode() { |
||||
# urlencode <string> |
||||
|
||||
local length="${#1}" |
||||
for (( i = 0; i < length; i++ )); do |
||||
local c="${1:i:1}" |
||||
case $c in |
||||
[a-zA-Z0-9.~_-]) printf "$c" ;; |
||||
*) eval printf '%s' '$c' | xxd -p -c1 | |
||||
while read c; do printf '%%%s' "$c"; done ;; |
||||
esac |
||||
done |
||||
} |
||||
|
||||
urlencode "$1" |
Loading…
Reference in new issue