-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtwitter_cleaner.py
executable file
·57 lines (43 loc) · 1.58 KB
/
twitter_cleaner.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
#
# Author: Osman Surkatty ([email protected])
#
# A simple script which can be used to periodically clean out your Twitter
# timeline.
from datetime import *
from twitter import *
import sys
import time
def lambda_handler(event, context):
older_than = 30 # days
# From: https://apps.twitter.com/ or https://developer.twitter.com/
token = ""
token_key = ""
con_secret = ""
con_secret_key = ""
t = Twitter(auth=OAuth(token, token_key, con_secret, con_secret_key))
favorites = t.favorites.list(count=200)
tweets = t.statuses.user_timeline(count=200)
deleted_tweets = 0
unfavorited_tweets = 0
while True:
if favorites:
fav = favorites.pop()
days_ago = (datetime.today() -
datetime.strptime(fav['created_at'], "%a %b %d %H:%M:%S +0000 %Y")).days
if days_ago > older_than:
print("[*] Unfavoriting tweet..")
t.favorites.destroy(_id=fav['id'])
unfavorited_tweets += 1
if tweets:
tweet = tweets.pop()
days_ago = (datetime.today() -
datetime.strptime(tweet['created_at'], "%a %b %d %H:%M:%S +0000 %Y")).days
if days_ago > older_than:
print("[*] Deleting tweet..")
t.statuses.destroy(_id=tweet['id'])
deleted_tweets += 1
if not favorites and not tweets:
break
print("[*] Deleted " + str(deleted_tweets) + " tweets and unfavorited " +
str(unfavorited_tweets) + " tweets.")