-
Notifications
You must be signed in to change notification settings - Fork 323
/
Copy pathtwitter-friendship.py
executable file
·46 lines (37 loc) · 1.86 KB
/
twitter-friendship.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
#!/usr/bin/env python3
#-----------------------------------------------------------------------
# twitter-friendship
# - outputs details of the relationship between two users.
#-----------------------------------------------------------------------
from twitter import *
#-----------------------------------------------------------------------
# load our API credentials
#-----------------------------------------------------------------------
import sys
sys.path.append(".")
import config
#-----------------------------------------------------------------------
# create twitter API object
#-----------------------------------------------------------------------
twitter = Twitter(auth=OAuth(config.access_key,
config.access_secret,
config.consumer_key,
config.consumer_secret))
#-----------------------------------------------------------------------
# the usernames whose relationship we want to examine
#-----------------------------------------------------------------------
source = "ideoforms"
target = "lewisrichard"
#-----------------------------------------------------------------------
# perform the API query
# twitter API docs: https://dev.twitter.com/rest/reference/get/friendships/show
#-----------------------------------------------------------------------
result = twitter.friendships.show(source_screen_name=source,
target_screen_name=target)
#-----------------------------------------------------------------------
# extract the relevant properties
#-----------------------------------------------------------------------
following = result["relationship"]["target"]["following"]
follows = result["relationship"]["target"]["followed_by"]
print("%s following %s: %s" % (source, target, follows))
print("%s following %s: %s" % (target, source, following))