Collect tweets with python. It is mainly used when you want to get information from XX bots when learning machines. (In the case of I) The contents of 〇〇bot etc. are very biased, For example, it can be said that there are many tweets about tsundere in tsundere bots. This is a collection of tsundere lines for this account, all of which can be recognized as tsundere lines, and to put it simply, a model of "spam or not", that is, tsundere classified as tsundere or not. Can be used for.
The introduction has been lengthened, but there are only a few lines of code to retrieve tweets. Library uses Tweepy, so if you don't have it installed
command
pip install tweepy
or
sudo easy_install tweepy
You can install it with.
You need to get CK, CS, AK, AT to actually work. Please create a new app from the URL below and get a Token https://apps.twitter.com/ get_timeline () for each (Id) of the account you want to get, Number of tweets to get (cout) Apply.
get_timeline
#coding: utf-8
import tweepy
CK = ""
CS = ""
AK = ""
AT = ""
def get_twitter_api(CK, CS, AK, AT):
auth = tweepy.OAuthHandler(CK, CS)
auth.set_access_token(AK, AT)
api = tweepy.API(auth)
return api
def get_timeline(id, count=100):
API = get_twitter_api(CK, CS, AK, AT)
i = API.user_timeline(id=id, count=count)
with open("", "w") as f:
for k in i:
encode = k.text+'\n'
f.write(encode.encode('utf-8'))
if __name__ == '__main__':
get_timeline(id="", count=100)
Recommended Posts