aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Mathes <amathes@gmail.com>2015-07-14 21:21:59 -0700
committerAdam Mathes <amathes@gmail.com>2015-07-14 21:21:59 -0700
commit915ae54e7e5dc639972a40d4a7817d20b54fc1e2 (patch)
tree88e054b1e7149de37fe79a328186972b579db576
parent549c3c2fef9e63262351513a5a20519892f72b26 (diff)
properly handle reply use case
-rw-r--r--example_settings.py1
-rw-r--r--unloved_tweets.py27
2 files changed, 26 insertions, 2 deletions
diff --git a/example_settings.py b/example_settings.py
index deba625..5657699 100644
--- a/example_settings.py
+++ b/example_settings.py
@@ -5,3 +5,4 @@ consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
+username = '@example'
diff --git a/unloved_tweets.py b/unloved_tweets.py
index c206d18..647bd38 100644
--- a/unloved_tweets.py
+++ b/unloved_tweets.py
@@ -7,21 +7,44 @@ auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
+tweet_ids_with_replies = []
+
+
+# grab mentions to get latest tweets to see if things were replied to
+# edge case: fails to work if there are 100 mentions on other tweets within 5 minutes
+# if this happens to you why are you using this script, also, sorry
+mentions = api.search(q=username)
+for mention in mentions:
+ parent_id = mention.in_reply_to_status_id
+ if parent_id:
+ tweet_ids_with_replies.append(parent_id)
+ if DEBUG:
+ print "adding %s to tweets with one or more replies" % mention.text
+
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 = tweet.favorite_count + tweet.retweet_count
- engagements = 0
- engagements = engagements + tweet.favorite_count + tweet.retweet_count
+ # tweet was a reply to another tweet
if tweet.in_reply_to_status_id:
engagements = engagements + 1
+ # tweet had one or more replies
+ if tweet.id in tweet_ids_with_replies:
+ engagements = engagements + 1
+
+
if DEBUG:
print "--------"
+ print tweet.id
+ print tweet.text
print "%d engagements after %d minutes" % (engagements, minutes)
+ if tweet.id in tweet_ids_with_replies:
+ print "has one or more replies!"
if minutes<60 and minutes>=MINUTES_TO_LIVE and engagements==0:
if DEBUG: