Skip to content

Instantly share code, notes, and snippets.

@mgarcia-org
Last active April 6, 2020 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgarcia-org/44cfb4a2d05114020e16e3bbb1c88969 to your computer and use it in GitHub Desktop.
Save mgarcia-org/44cfb4a2d05114020e16e3bbb1c88969 to your computer and use it in GitHub Desktop.
parity.py
'''
Unfollow friends that do not follow you.
https://github.com/geduldig/TwitterAPI/tree/master/examples
sudo apt-get update
sudo apt-get install python3
sudo apt-get install python2.7
sudo apt install python-pip
pip install --upgrade setuptools
pip install TwitterAPI
'''
import numbers
import time
from TwitterAPI import TwitterAPI
CONSUMER_KEY = ' '
CONSUMER_SECRET = ' '
ACCESS_TOKEN_KEY = ' '
ACCESS_TOKEN_SECRET = ' '
api = TwitterAPI(CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN_KEY,
ACCESS_TOKEN_SECRET)
print ''
print ''
print ''
print ''
print ''
print ''
print ''
print ''
print ''
print '---------------- starting ------------------'
print time.strftime("%Y-%m-%d %H:%M")
print '---------------- starting ------------------'
print ''
print ''
followers = []
for id in reversed(list(api.request('followers/ids'))):
# print 'followers %d' % id
followers.append(id)
time.sleep(3)
myFriends = []
for id in reversed(list(api.request('friends/ids'))):
# print 'I follow %d' % id
myFriends.append(id)
non_friends = [friend for friend in myFriends if friend not in followers]
to_follow = [following for following in followers if following not in myFriends]
print 'non_friends list len %d' % len(non_friends)
print 'to_follow list len %d' % len(to_follow)
time.sleep(3)
print 'following back starting now!'
for id in to_follow:
if isinstance(id, numbers.Integral):
print 'following %d' % id
print time.strftime("%Y-%m-%d %H:%M")
time.sleep(60) #5mins
r = api.request('friendships/create', {'user_id': id})
print 'result status_code %d' % r.status_code
if r.status_code == 200:
status = r.json()
print 'followed created %d' % id
time.sleep(60) #5mins
elif r.status_code == 429:
print 'timed out 15mins'
print time.strftime("%Y-%m-%d %H:%M")
time.sleep(950) #15mins
# time.sleep(300) #5mins
print 'timed out back again'
print time.strftime("time out now back: %Y-%m-%d %H:%M")
print time.strftime("%Y-%m-%d %H:%M")
print 'following back finished'
print ''
print ''
print ''
print ''
print 'unfollow starting now!'
for id in non_friends:
if isinstance(id, numbers.Integral):
print 'unfollowing %d' % id
print time.strftime("%Y-%m-%d %H:%M")
time.sleep(60) #5mins
r = api.request('friendships/destroy', {'user_id': id})
print 'result status_code %d' % r.status_code
if r.status_code == 200:
status = r.json()
print 'unfollowed created %d' % id
time.sleep(60) #5mins
elif r.status_code == 429:
print 'timed out 15mins'
print time.strftime("%Y-%m-%d %H:%M")
time.sleep(950) #15mins
# time.sleep(300) #5mins
print 'timed out back again'
print time.strftime("time out now back: %Y-%m-%d %H:%M")
print time.strftime("%Y-%m-%d %H:%M")
print 'unfollow finished'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment