aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Mathes <amathes@gmail.com>2015-07-12 13:06:23 -0700
committerAdam Mathes <amathes@gmail.com>2015-07-12 13:06:23 -0700
commit549c3c2fef9e63262351513a5a20519892f72b26 (patch)
tree73b32d0700b3f38724fd8b381fdc376569ed798c
initial commit
-rw-r--r--.gitignore1
-rw-r--r--example_settings.py7
-rw-r--r--readme.md51
-rw-r--r--unloved_tweets.py36
4 files changed, 95 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fce19e4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+settings.py
diff --git a/example_settings.py b/example_settings.py
new file mode 100644
index 0000000..deba625
--- /dev/null
+++ b/example_settings.py
@@ -0,0 +1,7 @@
+DEBUG = True
+MINUTES_TO_LIVE = 5
+DELETED_TWEETS_FILE = '/home/unloved_tweets/dead_tweets.txt'
+consumer_key = ''
+consumer_secret = ''
+access_token = ''
+access_token_secret = ''
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..f120965
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,51 @@
+# unloved_tweets
+
+This is a simple script to delete your tweets after a few minutes if nobody likes them.
+
+Never face the embarrassment of a zero-starred tweet again!
+
+## installation
+
+install dependencies (modern python, tweepy)
+
+## configuration
+
+copy example_settings.py to settings.py and fill in the required twitter api keys
+
+## running
+
+by default it runs in DEBUG mode and DELETES NOTHING
+
+Verify it's working reasonably with -
+
+ $ python unloved_tweets.py
+
+After that change DEBUG to false in your settings.py
+
+you probably will want to put this in your crontab with something like
+
+ */5 * * * * python ~/src_to_script/unloved_tweets.py
+
+## license
+
+The MIT License (MIT)
+
+Copyright (c) 2015 Adam Mathes
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/unloved_tweets.py b/unloved_tweets.py
new file mode 100644
index 0000000..c206d18
--- /dev/null
+++ b/unloved_tweets.py
@@ -0,0 +1,36 @@
+import tweepy
+import datetime
+import math
+from settings import *
+
+auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
+auth.set_access_token(access_token, access_token_secret)
+api = tweepy.API(auth)
+
+
+public_tweets = api.user_timeline()
+for tweet in public_tweets:
+ lifetime = datetime.datetime.utcnow()-tweet.created_at
+ minutes = math.floor(lifetime.total_seconds() / 60)
+
+
+ engagements = 0
+ engagements = engagements + tweet.favorite_count + tweet.retweet_count
+ if tweet.in_reply_to_status_id:
+ engagements = engagements + 1
+
+ if DEBUG:
+ print "--------"
+ print "%d engagements after %d minutes" % (engagements, minutes)
+
+ if minutes<60 and minutes>=MINUTES_TO_LIVE and engagements==0:
+ if DEBUG:
+ print "DELETING " + str(tweet.id)
+ print tweet.text
+
+ with open(DELETED_TWEETS_FILE, "a") as f:
+ f.write( tweet.text.encode('utf8') )
+ f.write("\n\n")
+
+ if not DEBUG:
+ api.destroy_status(tweet.id)