# where tweets are not in "saved" list and older than cutoff date if ("Anna" not in tweet.text and tweet.created_at < cutoff_date and tweet.retweeted == True and tweet.retweet_count < RETWEETED_BLOCK) or ("Anna" not in tweet.text and tweet.created_at <= cutoff_date and tweet.retweeted == False and tweet.retweet_count < RETWEET_BLOCK and tweet.favorite_count < FAVORITE_BLOCK): # Checks if there is media associated with the tweet media = tweet.entities.get('media', []) if(len(media) > 0): filename = wget.download(media[0]['media_url']) csvWriter.writerow([tweet.id, tweet.created_at, tweet.text, filename]) print (("Deleting %d: [%s] %s" % (tweet.id, tweet.created_at, tweet.text)).encode("utf-8")) if not test_mode: try: api.destroy_status(tweet.id) print (("Deleting %d: [%s] %s" % (tweet.id, tweet.created_at, tweet.text)).encode("utf-8")) except: print (("Failed to delete %d: [%s] %s" % (tweet.id, tweet.created_at, tweet.text)).encode("utf-8")) deleted_count += 1 else: ignored_count += 1 print ("Deleted %d tweets, ignored %d" % (deleted_count, ignored_count)) else: print ("No tweets were deleted") csvFile.close() if __name__ == "__main__": api = twitterLogin.oauth_login(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET) print ("Authenticated as @%s" % api.me().screen_name) tweet_delete()
Description: This script allows the user to tweet from the command line. """ import tweepy import sys import time import threading import twitterLogin #TODO # Implement 0-140 character check # Tweets the time every minute def send_scheduled_tweet(): api.update_status(time.ctime()) print("Tweet sent by @%s" % api.me().screen_name) threading.Timer(60, send_tweet).start() # Tweets user input from command line def send_tweet(tweet): api.update_status(tweet) print("Tweet sent by @%s" % api.me().screen_name) if __name__ == "__main__": api = twitterLogin.oauth_login(twitterLogin.CONSUMER_KEY, twitterLogin.CONSUMER_SECRET) print ("Authenticated as @%s" % api.me().screen_name) send_tweet(sys.argv[1])