1
0

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 2021-12-13

引用RTに引用RTで返す

  • 引用RTとは「会話」ではなく「攻撃」である
    • つまり攻撃に対する防衛である
    • 闇のプログラミングではあるが、闇の魔術に対する防衛術である

仕様

  • 前提としてアカウント名にアンスコが入ってると出来ない
    • 検索クエリを検索APIで叩いているだけなので、API経由でもこれは同じである

コード

  • auth_api(tweetUtil.py)は前回の記事にあるのでそちらを参照
quoteRtReply.py
import sys
from tweetUtil import auth_api
import csv

def main():
    # 引用RTに添える文字列
    text = "やはり。あからさま。"
    # get args
    envName = sys.argv[1]
    # Twitter auth
    api = auth_api(envName)
    # search query
    userName = api.me().screen_name
    word = "twitter.com/" + userName + ' /-from:' + userName
    # search
    set_count = "100"
    results = api.search(q=word, count=set_count)
    csvname = envName + "_quotedIds.csv"
    mentionedIds = []
    with open(csvname) as f:
        quotedIds = [int(s.strip()) for s in f.readlines()]
    print(quotedIds)
    for i in results:
        if i.is_quote_status == True and i.id not in quotedIds:
            print([i.id, i.user.screen_name, i.text, i.created_at])
            qrturl = "https://twitter.com/" + \
                str(i.user.screen_name) + "/status/" + str(i.id)
            print(qrturl)
            api.update_status(status=text + " " + qrturl)
            mentionedIds.append([i.id])
        else:
            pass
    # write csv
    with open(csvname, 'a', newline='', encoding='utf-8') as f:
        writer = csv.writer(f, lineterminator='\n')
        writer.writerows(mentionedIds)
    pass


if __name__ == "__main__":
    main()

実行

touch nogaslighting_quotedIds.csv
python quoteRtReply.py nogaslighting

今後

  • cronで動かしているが、Stateファイル(csv)をS3に置けばLambda+S3のサーバレスアーキテクチャになるので検討
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?