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 1 year has passed since last update.

特定アカウントの鍵垢フォロワーにまとめてフォローリクエストを送る

Last updated at Posted at 2022-04-14

準備

  • 認証ファイルはconfig parserを使う
setting.ini
[conf_name]
consumer_key = xxxx
consumer_secret = xxxx
access_key = xx-xx
access_secret = xxx

コード

protectAccountAllFollow.py
import tweepy
import sys
import configparser


def auth_api(envName):
    # 認証
    config = configparser.ConfigParser()
    config.read('setting.ini')
    print("envName is " + envName)
    consumer_key = config.get(envName, 'consumer_key')
    consumer_secret = config.get(envName, 'consumer_secret')
    access_key = config.get(envName, 'access_key')
    access_secret = config.get(envName, 'access_secret')
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)
    return api


def getFollowers_ids(Api, Id):
    # フォロワー取得
    followers_ids = tweepy.Cursor(Api.followers_ids, id=Id, cursor=-1).items()
    followers_ids_list = []
    for followers_id in followers_ids:
        followers_ids_list.append(followers_id)
    return followers_ids_list


def protectAccountAllFollow(api, f_list):
    # 鍵垢をまとめてフォロー
    for i in f_list:
        usr = api.get_user(i)
        if usr.protected:
            print(usr.screen_name, usr.name)
            api.create_friendship(i)


def main():
    # メイン処理
    target_screen_name = sys.argv[1]
    api_key = sys.argv[2]
    api = auth_api(api_key)
    f_list = getFollowers_ids(api, target_screen_name)
    protectAccountAllFollow(api, f_list)


if __name__ == "__main__":
    main()

実行

protectAccountAllFollow.py ${ターゲットのスクリーンネーム} ${setting.iniに記載したconf名}

普通に嫌われるのでやめましょう

  • 普通に嫌われるのでやめましょう
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?