-
Notifications
You must be signed in to change notification settings - Fork 0
/
unfollow.py
executable file
·48 lines (32 loc) · 1.37 KB
/
unfollow.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
#! /usr/bin/env python
from sys import argv, exit
from requests import Session
from requests_foauth import Foauth
if __name__ == '__main__':
try:
email, password = argv[1], argv[2]
except IndexError:
print 'Usage: unfollow.py <foauth.org email> <foauth.org password>'
exit(1)
foauth = Foauth(email, password)
session = Session()
session.mount('https://', foauth)
authentication_response = session.get('https://api.twitter.com/1.1/account/verify_credentials.json')
if authentication_response.status_code != 200:
print authentication_response.status_code, authentication_response.content
exit(1)
followers_response = session.get('https://api.twitter.com/1.1/followers/ids.json')
followers = followers_response.json()
followers = followers['ids']
followers = frozenset(followers)
following_response = session.get('https://api.twitter.com/1.1/friends/ids.json')
following = following_response.json()
following = following['ids']
following = frozenset(following)
to_unfollow = following - followers
for user in to_unfollow:
unfollow_response = session.post('https://api.twitter.com/1.1/friendships/destroy.json', {
'user_id': user,
})
if unfollow_response.status_code != 200:
print unfollow_response.status_code, unfollow_response.text