Skip to content

Instantly share code, notes, and snippets.

@y-gagar1n
Last active July 16, 2018 08:00
Show Gist options
  • Save y-gagar1n/0f873da67f0b11f8fdb5bbeaf6b764c0 to your computer and use it in GitHub Desktop.
Save y-gagar1n/0f873da67f0b11f8fdb5bbeaf6b764c0 to your computer and use it in GitHub Desktop.
import twitter
import config
import datetime
import time
api = twitter.Api(consumer_key=config.CONSUMER_KEY,
consumer_secret=config.CONSUMER_SECRET,
access_token_key=config.ACCESS_TOKEN_KEY,
access_token_secret=config.ACCESS_TOKEN_SECRET,
sleep_on_rate_limit=True)
delta = datetime.timedelta(days=3*365)
earliestDt = datetime.datetime.now() - delta
earliest = time.mktime(earliestDt.timetuple())
blacklist = []
friends = api.GetFriendIDs()
followers = api.GetFollowers()
c = 0
for follower in followers:
c = c + 1
print("processing %d of %d" % (c, len(followers)))
id = follower.id
screen_name = follower.screen_name
if not id in friends:
try:
timeline = api.GetUserTimeline(id, count=1, trim_user=True)
if(len(timeline) == 0):
blacklist.append((id, screen_name))
else:
last_status = timeline[0]
created_at = last_status.created_at_in_seconds
if(created_at < earliest):
blacklist.append((id, screen_name))
except:
print("error on %s" % screen_name)
blacklist.append((id, screen_name))
for id, name in blacklist:
print("blocking " + name)
api.CreateBlock(user_id=id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment