楽天モバイル基地局のハッシュタグをリツイート

import datetime
import tweepy

consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
bearer_token = ""


def rakuten_tweet(tweets):

    for tweet in tweets.data:

        s = tweet.data.get("created_at")

        if s:

            created = datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S.%fZ")

            if created > start_time:

                entities = tweet.data.get("entities")

                if entities:

                    if not tweet.text.startswith("RT"):

                        tags = {i.get("tag") for i in entities.get("hashtags", {})}

                        if hashtag <= tags:

                            client.retweet(tweet.id)
                            print(tweet.text)


client = tweepy.Client(
    bearer_token, consumer_key, consumer_secret, access_token, access_token_secret
)


hashtag = {"愛媛", "楽天モバイル", "基地局"}


dt_now = datetime.datetime.utcnow()
dt_now

start_time = dt_now - datetime.timedelta(hours=6, minutes=5)
start_time

raku10ehime = client.get_user(username="raku10ehime").data
raku10ehime

# リスト確認
lists = {i["name"]: i["id"] for i in client.get_owned_lists(raku10ehime.id).data}

tweets = client.get_list_tweets(
    id=lists["ehime"], tweet_fields=["entities", "created_at"], max_results=100
)

rakuten_tweet(tweets)