@yucha53 (ゆ ゆ)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

tweepy で1週間以上前のツイートを収集する方法

プログラミング初心者です・・・

解決したいこと

tweepyを使って1週間以上前のツイートを収集したいと思っています。
期間を設定すると動かない?何も出てこなくなってしまいます・・・

該当するソースコード

こうするとうまくいくのですが・・・

言語名 google.colaboratory を使っています。

sinceDate ='2021-09-01 00:00:00'
untilDate='2021-09-07 00:00:00'
q='コロナ'
sratchStr=q+'since:'+sinceDate+'until:'+untilDate+'exclude:retweets'
print('検索:'+sratchStr)

tweets=tweepy.Cursor(api.search,q=q,include_untities=True,tweet_mode='extended',lang='ja',since=sinceDate,until=untilDate).items()

tweet_list=[]

for tweet in tweets:
  tweet_list.append([tweet.created_at])
  tweet_list.append([tweet.user.screen_name,tweet.full_text])
  print('============')
  print('user : ',tweet.user.screen_name)
  print('date : ',tweet.created_at)
  print(tweet.full_text)

期間を変えて、行ってみると動きません。

sinceDate ='2021-01-01 00:00:00'
untilDate='2021-01-07 00:00:00'
q='コロナ'
sratchStr=q+'since:'+sinceDate+'until:'+untilDate+'exclude:retweets'
print('検索:'+sratchStr)
tweets=tweepy.Cursor(api.search,q=q,include_untities=True,tweet_mode='extended',lang='ja',since=sinceDate,until=untilDate).items()

tweet_list=[]

for tweet in tweets:
  tweet_list.append([tweet.created_at])
  tweet_list.append([tweet.user.screen_name,tweet.full_text])
  print('============')
  print('user : ',tweet.user.screen_name)
  print('date : ',tweet.created_at)
  print(tweet.full_text)

自分で試したこと

2つ目を実行してみても、エラーも何も出ず、、、
なにが起こっているのか分かりません。

1週間以上前のツイートは収集できないということでしょうか?
色々と調べていると、「1週間以上前のツイートでも収集できる方法がある」とありましたが、
ご存じの方いらっしゃれば、1週間以上前のツイート収集方法を教えて頂きたいです。

0 likes

2Answer

結果に関係があるかは不明ですが、sinceDateのコロンが全角になっているのが気になりますね。

0Like

Search API では過去7日以内のツイートしか取得できません。

until optional Returns tweets created before the given date. Date should be formatted as YYYY-MM-DD. Keep in mind that the search index has a 7-day limit. In other words, no tweets will be found for a date older than one week.

0Like

Your answer might help someone💌