0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tweepyを使用して、特定地域の特定文言ツイート件数を調査する

0
Last updated at Posted at 2020-09-20

【要件】
twitter.apiを用いて
特定の文言(涼しい)が含まれる直近100件のツイートを抽出した後
ツイート元ユーザのプロフィールに記載された所在地に
"東京"が何件含まれているかをアウトプットしてくれるプログラムをつくる
(今日はとても涼しかったので作成してみました)

【暫定的に作成したプログラム(locationの検索が可能かどうかテスト)】

get_timeline_specificword.py
import tweepy
import csv


# APIの秘密鍵
consumer_key = 'XXXX' # コンシューマーキー
consumer_secret = 'XXXX' # コンシューマーシークレット
access_token = 'XXXX' # アクセストークン
access_token_secret = 'XXXX' # アクセストークンシークレット


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

for tweet in tweepy.Cursor(api.search,q='涼しい').items(100):
    print(tweet.user.location)
    LOCATE = tweet.user.location
    print('東京' in LOCATE)
【実行結果】
東京都八丈島
Traceback (most recent call last):
  File "get_timeline_specificword.py", line 20, in <module>
    print('東京' in LOCATE)
TypeError: argument of type 'NoneType' is not iterable

【原因】
変数LOCATEの型がNonetypeとなっていた(;^_^A
【修正】
inで使える型にする為、str(LOCATE)として修正。

【修正後実行結果(抜粋)】
False
横浜在住
False
日本 東京 Tokyo
True

一応解決したようだ('ω')ノ
ツールとしてはまだまだ改良の余地がありそうですね。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?