I found a Twitter client for Python called tweepy, so I played around with it. In the first place, I don't usually use Twitter, so in my case, I can't use it when I made it. .. ..
First of all, as an implementation ・ Token issuance ・ Delete tweets ・ Unrequited love or follow ・ Follow users who are following a specific account The definition of unrequited love is here
I will explain the function name and processing respectively. deletion(self, id, count=200) --id = account id (@XXX) --count = number This function gets the tweet of id specified by argument id by argument count Delete. This function works if the token is the same as that of id. Of course, you cannot delete other people's tweets.
destroy(self, id) --id = account id (@XXX) This function unfollows a user whose id specified by the argument id is unrequited love (definition 1).
create(self, id) --id = account id (@XXX) This function follows a user whose id specified by the argument id is unrequited love (definition 2).
follow(self, id) --id = account id (@XXX) This function follows the user who is following the user with the id specified by the argument id.
class Token:
def __init__(self, consumer_key, consumer_secret):
self.auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
def GET(self):
redirect_url = self.auth.get_authorization_url()
print "URL: %s" % (str(redirect_url))
self.auth.get_access_token(raw_input('code: ').strip())
return [self.auth.access_token, self.auth.access_token_secret]
class Twitter_Class:
def __init__(self, consumer_key, consumer_secret, access_token, access_secret):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
self.api = tweepy.API(auth)
def deletion(self, id, count=200):
try:
map(self.api.destroy_status, [i.id for i in self.api.user_timeline(id, count=count)])
except Exception, e:
print e
def destroy(self, id):
try:
friends_ids = self.api.friends_ids(id)
followers_ids = self.api.followers_ids(id)
list_ = []
for i in friends_ids:
if not i in followers_ids:
list_.append(i)
map(self.api.destroy_friendship, list_)
except Exception, e:
print e
def create(self, id):
try:
followers_ids = self.api.followers_ids(id)
friends_ids = self.api.friends_ids(id)
list_ = []
for i in followers_ids:
if not i in friends_ids:
list_.append(i)
map(self.api.create_friendship, list_)
except Exception, e:
print e
def follow(self, id):
try:
friends = self.api.friends_ids(id)
count = 0
for i in friends:
if count < 50:
self.api.create_friendship(i)
else:
[time.sleep(18) for i in range(100)]
count = 0
except Exception, e:
print e
Recommended Posts