aboutsummaryrefslogtreecommitdiffstats
path: root/unloved_tweets.py
blob: c206d18815cb587a27892c9e197aff42bb389f64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)