setã使ã£ã¦ãtwitterã®çæããçæããã両æããåå¾ãã
@tohae_callã¨ããbotãä½ã£ã¦ããã®ã§ãããä»ã¾ã§ã¯followãã¦ããã人ãæåã§followè¿ããã¦ãã®ã§ãããæè¿@tohae_callãremoveãã人ãå¢ãã¦ãã¦ããããã«æåremoveã¯ããã©ãããããã®ã§ã両æ¹ã¨ãèªååãããã¨ã«ãã¾ããã
ãã®ããã«ã¯ãçæãã¨çæããã®ãªã¹ããåå¾ããå¿
è¦ãããã®ã§ãããpythonã®set*1ã使ã£ã¦ãå·®éåãæ±ããã®ãä¸çªç°¡åã§ãã
setã¯éåã表ç¾ãããã®ãªã®ã§ãããæ¼ç®åããªã¼ãã¼ãã¼ã*2ãã¦ãããããåéåãå·®éåãç©éåãpythonã®æ¼ç®åãç¨ãã¦è¡¨ç¾ã§ãã¾ãã
setã使ã£ã¦å·®éåãæ±ããåã«ãã¾ãã¯twitterã®followingã¨followerã®åå¾ãå¿
è¦ã§ããtwitterã«ã¯followingã¨followerã®idã ãã®ãªã¹ããè¿ãAPIãããã®ã§ãããã使ãã¾ãã以ä¸ãµã³ãã«
import json import urllib2 def getFollowers(screen_name="tohae_call"): url = "http://twitter.com/followers/ids/%s.json" % screen_name ids = urllib2.urlopen(url).read() return json.loads(ids) def getFollowing(screen_name="tohae_call"): url = "http://twitter.com/friends/ids/%s.json" % screen_name ids = urllib2.urlopen(url).read() return json.loads(ids)
getFollowersã§followerããgetFollowingã§followingãåå¾ãã¾ãããããç¨ãã¦ãçæãã¨çæããã®IDã®ãªã¹ããåå¾ãã¾ãã以ä¸ãµã³ãã«
following_set = set(getFollowing()) follower_set = set(getFollowers()) #çæã kataomoi = following_set - follower_set #çæãã kataomoware = followe_set - following_set #両æã ryouomoi = follower_set & following_set
ãã¨ã¯ãããã¦åå¾ãããçæããªã¹ãã«ããIDãremoveãã¦ãçæãããªã¹ãã«ããIDãfollowããã ãã§ãã
ãï¼ç°¡åã§ããï¼