34
loading...
This website collects cookies to deliver better user experience
python -m pip install -r requirements.txt
config.read('..\..\TwitterAPI\config.ini')
import configparser
import tweepy
from datetime import date
config = configparser.ConfigParser()
config.read('..\..\TwitterAPI\config.ini')
[API]
Key = <your api key>
Secret = <your api secret>
[Bearer]
Token = <your bearer token, for >
[Acess]
Token = <your access token>
Secret = <your access secret>
[General]
ScreenName = <the target user>
BatchSize = 10
DaysInactive = 5
auth = tweepy.OAuthHandler(config['API']['Key'], config['API']['Secret'])
auth.set_access_token(config['Acess']['Token'], config['Acess']['Secret'])
api = tweepy.API(auth, wait_on_rate_limit=True)
user = api.get_user(screen_name=config['General']['ScreenName'])
inactive_friends = [];
for friend in tweepy.Cursor(api.get_friends, screen_name=user.screen_name).items():
tweets_list= api.user_timeline(screen_name = friend.screen_name, count = 1)
tweet= tweets_list[0] # last status of this friend (tweepy.models.Status)
delta = date.today() - tweet.created_at.date()
if (delta.days > int(config['General']['DaysInactive'])):
inactive_friends.append(friend)
if (len(inactive_friends) >= int(config['General']['BatchSize'])):
break
if (len(inactive_friends) > 0):
print('The following % s friends are inactive for more than 5 days:' % len(inactive_friends))
for friend in inactive_friends:
print(friend.screen_name)
print('Unfollowing %s inactive users..' % len(inactive_friends))
answer = input("Are you sure? [Y/n]").lower()
if answer and answer[0] == "y":
for friend in inactive_friends:
print("Unfollowing " + friend.screen_name)
friend.unfollow()