diff options
| author | Adam Mathes <amathes@gmail.com> | 2015-07-14 21:21:59 -0700 | 
|---|---|---|
| committer | Adam Mathes <amathes@gmail.com> | 2015-07-14 21:21:59 -0700 | 
| commit | 915ae54e7e5dc639972a40d4a7817d20b54fc1e2 (patch) | |
| tree | 88e054b1e7149de37fe79a328186972b579db576 /unloved_tweets.py | |
| parent | 549c3c2fef9e63262351513a5a20519892f72b26 (diff) | |
properly handle reply use case
Diffstat (limited to 'unloved_tweets.py')
| -rw-r--r-- | unloved_tweets.py | 27 | 
1 files changed, 25 insertions, 2 deletions
| 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: | 
