Skip to content

Commit

Permalink
Properly added ability to do retweets by setting that as tweetype and…
Browse files Browse the repository at this point in the history
… setting 'tweetcontent' to the tweet ID
  • Loading branch information
pattonwebz committed Aug 6, 2016
1 parent d15a3a1 commit b60de0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
11 changes: 7 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ 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)
selectResult = cursor.fetchall()


## 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:

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions twitterfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b60de0c

Please sign in to comment.