From b60de0c921102f2f41e7b502714a3dc37bc7470e Mon Sep 17 00:00:00 2001 From: willampatton Date: Sat, 6 Aug 2016 16:38:34 +0100 Subject: [PATCH] Properly added ability to do retweets by setting that as tweetype and setting 'tweetcontent' to the tweet ID --- add.py | 2 +- bot.py | 11 +++++++---- twitterfunctions.py | 4 ++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/add.py b/add.py index ad9dcdb..abecd6a 100644 --- a/add.py +++ b/add.py @@ -56,7 +56,7 @@ def tweetValidate(tweet_text, tweet_type): MAXTCOLENGTH = 20 charCount = len(tweet_text) - if ( tweet_type == 'retweet' and charCount > 16 ) : + if ( tweet_type == 'retweet' and charCount > 18 ) : print ("error with retweet length") if charCount > 140 : diff --git a/bot.py b/bot.py index f03f3c7..a84191f 100755 --- a/bot.py +++ b/bot.py @@ -93,7 +93,7 @@ def runner(dbconfig, waitTime): cursor = dbconnect.dbcursor(cnx) ## query for ScheduledTweets that are not sent yet - selectQuery = ("SELECT id, tweetcontent, timetosend, sent FROM ScheduledTweets WHERE sent = 0") + selectQuery = ("SELECT id, tweetcontent, timetosend, sent, tweettype FROM ScheduledTweets WHERE sent = 0") ## execute the query and return the result to an array cursor.execute(selectQuery) @@ -101,7 +101,7 @@ def runner(dbconfig, waitTime): ## loop through the results - for (id, tweetcontent, timetosend, send) in selectResult: + for (id, tweetcontent, timetosend, send, tweettype) in selectResult: ## if not sent yet if send == 0: @@ -120,8 +120,11 @@ def runner(dbconfig, waitTime): "timesent = NULL " "WHERE id = %d" % (id)) - ## send the tweet - twitterfunctions.sendtweet(authenticated_api, tweetcontent) + ## send the tweet or retweet + if tweettype == 'retweet' : + twitter.functions.sendretweet(authenticated_api, tweetcontent) + elif tweettype == 'tweet' : + twitterfunctions.sendtweet(authenticated_api, tweetcontent) ## run the update query and commit to the databse cursor.execute(updateQuery) diff --git a/twitterfunctions.py b/twitterfunctions.py index 1c4fc6c..dde09b3 100755 --- a/twitterfunctions.py +++ b/twitterfunctions.py @@ -25,3 +25,7 @@ def authenticatetwitter(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY, ACCESS_SECRET def sendtweet(api, tweet): # Send 'tweet' using Tweepy API function api.update_status(status=tweet) + +def sendretweet(api, tweet): + # Send a retweet - 'tweet' content will be a tweet Id + api.retweet(tweet)