<jupyter_start><jupyter_text><jupyter_code>!pip install tweepy
import time
import tweepy
import random
import os
import datetime
consumer_key = '' # Consumer API key
consumer_secret = '' # Consumer API Secret key
access_token_key = '-' # Access token
access_token_secret = '' # Access token secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
api = tweepy.API(auth)
my_user_id = ''
 def search_tweets(q, sinceDate):
    for i in range(3):
        try:
          results = tweepy.Cursor(api.search, q=q, tweet_mode='extended', since = sinceDate, result_type="mixed", include_entities=True).items()
        except tweepy.RateLimitError as e:
            print(e)
            time.sleep(15 * 60)
        except tweepy.TweepError as e:
            print(e)
            time.sleep(5 * 60)
            break
        else:
            return results
def create_frend(q, todaystr, sinceDate):

    # Twitterの検索結果を取得
    results = search_tweets(q, sinceDate)

    for result in results:
        screen_name = result.user.screen_name
        is_following = result.user._json['following']
        if screen_name == my_user_id:
            print('自分')
        else:
            if is_following:
                print('@' + screen_name + 'はフォロー済み')
                time.sleep(30)
            else:
                print('@' + screen_name + 'をフォロー処理中...')
                for i in range(3):
                    try:
                        api.create_friendship(screen_name)
                        print('フォローに成功しました')
                    except tweepy.RateLimitError as e:
                        print(e)
                        time.sleep(15 * 60)
                    except tweepy.TweepError as e:
                        print(e)
                        time.sleep(5 * 60)
                        break
                    else:
                        time.sleep(3 * 60)
                        break
def main():

    while True:
    #今日日付と過去の一覧を取得したい日付を設定
        today = datetime.date.today()
        todaystr = today.strftime('%Y%m%d')

        q = f"%23おはようVtubar"
        create_frend(q, todaystr, today - datetime.timedelta(days=1))

if __name__ == "__main__":
    main()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09542656112576957, 'fraction_numerical': 0.010554089709762533, 'mean_word_length': 1.767639902676399, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '186512', 'license': 'MIT', 'n_tokens_mistral': 749, 'n_tokens_neox': 707, 'n_words': 147, 'path': 'FriendsMaker.ipynb', 'repo_name': 'GTea-R/FriendsMaker', 'size': '2274'}