Code Monkey home page Code Monkey logo

luv-t-archive's Introduction

luv-t-archive

Twitter でいいねした画像/動画を自動で保存します🤖


luv-t-archive は自分が twitter で favorite/like したツイートを取得、spreadsheet に列挙し、画像・動画を google drive に保存します。
この repository を Fork し必要なTokenSettings > Secretsに登録すれば自動で収集する様になっています。

JA | EN

Setup

必要なもの

  • Google アカウント (GCP アカウント)
  • Twitter アカウント
    • 開発者申請をする必要がある

準備

  1. GCP Service Account を作成します (https://console.cloud.google.com/)
  2. Drive APISheets API を有効化し、JSON タイプのキーを作成し、保存しておきます
    1. Drive APISheets API を有効化します (https://console.cloud.google.com/apis/library)
    2. 作成したサービスアカウントを選択肢、JSON タイプのキーを作成し、保存しておきます (https://console.cloud.google.com/iam-admin/serviceaccounts)
  3. ファイルリストを保存する為に、Google Spreadsheets に新しいシートを作ります (https://docs.google.com/spreadsheets)
    1. その ID とシートの名前をコピーしておきます
    2. そのシートに上記で作成したサービスアカウントに共有設定します
  4. ファイルを保存する為に、Google Drive にフォルダを作ります (https://drive.google.com/drive)
    1. その ID をコピーしておきます
    2. そのフォルダに上記で作成したサービスアカウントに共有設定します
  5. Twitter Developers ページで、任意のアカウントでログインします (https://developer.twitter.com/en/apps/)
    1. 新しい App を作成するために開発者申請をします
    2. 新しい App を作成し、Bearer Token を作成し、それをコピーしておきます
  6. 利用したい Twitter Account の ID をコピーしておきます

始めるために

  1. この repository を Fork します
  2. .github/workflows/schedule.yml環境変数 を編集します:
    • TWITTER_ID: 利用する Twitter の ID
    • SHEET_NAME: 利用する Spreadsheets の名前 (Sheet1/シート 1)
  3. repository の Settings > Secrets へ行きます
  4. 以下の環境変数を追加します:
    • TWITTER_TOKEN: 上記で生成された Twitter の Bearer Token
    • SHEET_ID: 利用する Spreadsheets のシート ID: https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxx/edit
    • DRIVE_FOLDER_ID: 利用する Drive のシート ID: https://drive.google.com/drive/folders/xxxxxxxxxxxxxxxxxxxx.
    • SERVICE_CLIENT_EMAIL: 上記で保存したサービスアカウントのJSON 鍵のclient_email 部分
    • SERVICE_PRIVATE_KEY: 上記で保存したサービスアカウントのJSON 鍵のprivate_key 部分
      • 改行コードが含まれていると上手く動かないので除去し、改行する
      • $ echo "実際のkey" などすると良い感じ出力される

進捗

  • ツイートを取得
  • 取得したツイートとスプレッドシートを比較
  • スプレッドシートにツイートを整形し、保存
  • ツイートの画像・動画をドライヴに保存
  • ドライヴに保存中、エラーが起きた際のハンドリング
  • CI の設定
  • CI のエラーハンドリング(何故かエラーでも正常と処理されてる)

仕様

  1. 実行につき最新 200 いいね分遡ります
  2. 画像・動画があるツイートを抽出し、重複したものを Spreadsheets を参照し省き、Drive に保存します
    • GCP の limit により、一回に保存できる件数を 90 件にしています
    • 古い順に保存されるので、次回の実行までに 90 ツイート分いいねしなければ漏れはそこまで出ないはず・・・
  3. Drive に保存したファイルのリストを Spreadsheets に保存します
    • 消したりエラーが出ちゃうと Drive に保存するファイルが重複しちゃうので注意が必要です
      • 少なくとも実行の間隔を 2 分空けてください
    • Deive を参照したいが API の仕様上、ファイルリストを何回もリクエストする必要があるので現実的では無い・・・
    • API のリクエスト上限を上げれば良いが自己責任で

License

MIT ©ivgtr

Github Follow MIT License Donate CI

luv-t-archive's People

Contributors

ivgtr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.