I made a process to search Twitter by keyword with tweepy and write the result to Excel, so make a note of it.
See below. http://statsbeginner.hatenablog.com/entry/2015/10/21/131717 http://kasoutuuka.org/twitter-tweepy http://qiita.com/Kamo3167/items/b13531938a68234f19bf http://kivantium.hateblo.jp/entry/2015/01/03/000225
# -*- coding:utf-8 -*-
import tweepy
import datetime
import xlsxwriter
#Get key
CONSUMER_KEY = '****************'
CONSUMER_SECRET = '****************'
#Create an instance of the OAuthHandler class
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = '****************'
ACCESS_SECRET = '****************'
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
#OAuth authentication
api = tweepy.API(auth)
wb = xlsxwriter.Workbook('tweet.xlsx')
ws = wb.add_worksheet("teet")
#Creating an excel header
format = wb.add_format()
format.set_num_format('yy/mm/dd')
ws.write(0, 0, "name")
ws.write(0, 1, "user name")
ws.write(0, 2, "tweet")
ws.write(0, 3, "create date")
i = 1
#Search in twitter and write the result to excel
for status in api.search(q='"Aikatsu"', lang='ja', result_type='recent',count=100):
ws.write(i, 0, status.user.name)
ws.write(i, 1, status.user.screen_name)
ws.write(i, 2, status.text)
ws.write(i, 3, status.created_at+ datetime.timedelta(hours=9),format)
i = i + 1
wb.close()
Write your name, user name, tweet, and posting date in Excel like this.
--Create a Twitter account (of course) -Register the application with Twitter Application Management
I register with Twitter Application Management, but a website is required, but I don't use such a thing, so if you enter an appropriate URL, it's OK.
One thing to keep in mind when registering is that you need a ** phone number ** for your Twitter account. When I registered the phone number, I entered the phone number and the 6-digit number sent to the SMS, but I couldn't register even though I had the phone number and the 6-digit verification number.
The cause is that the phone number has a leading 0. If 090-XXXX-YYYY, it must be 90XXXXYYYY. http://qiita.com/tk1024/items/644ead20793a6e869b83
If you can register the application, make a note of the following
Coding is about OAuth authentication with the key information noted above, so only for searching.
ʻApi.search (q ='"Aikatsu "', lang ='ja', result_type ='recent', count = 100): ` This process searches for "Aikatsu" on Twitter as a keyword, and extracts only the regions of Japan. Get the latest 100 tweets.
Due to the specifications of tweepy, the maximum number of tweets that can be acquired is 100, so even if you do 101, you can only acquire 100.
See below for detailed settings. https://syncer.jp/twitter-api-matome/get/search/tweets
Since the upper limit of the number of acquired tweets is 100, I have the impression that it is difficult to analyze using this. The implementation itself is easy, and in addition to getting tweets, you can also tweet itself, so I wonder if it could be used for automatic tweets or something like that.
Recommended Posts