自分の過去のTweetを検索する方法

ツイ廃ツールを作ってしまった。。
Added by kanata 8 months ago

OwnTweetSearch

自分の過去のTweetを検索する方法

Twitterしてると、たまに「あぁ~このタイムラインの話題、あの時つぶやいたあの話なんだよな~」と思う時があります
でも、後の祭りでなかなか検索できないんですよね
そんな訳で簡単に検索できるツールを作りました

前提

以下のコマンドが使える環境があること、仮想環境のLinuxとかWSLとか
Macは動かない気がするけど、中身をちょっと書き換えればいけると思う

  • jq,sed,awk,grep,tail

準備(自分の全ツイート履歴のダウンロード)

Twitterは自分の過去ツイートの全データをダウンロードできます
以下の手順を基にダウンロードします

zipで提供されるはずですので、中身を展開して確認しましょう
この中の tweet.js だけが必要です

OwnTweetSearch の導入

install

ダウンロードして、実行権つけて、一箇所中身の設定項目を書き換えるだけ

$ wget https://raintrees.net/attachments/download/709/OwnTweetSearch.sh
$ chmod u+x ./OwnTweetSearch.sh
$ vi OwnTweetSearch.sh
- MY_NAME="own-twitter-id" #自身のTwitterのidを設定
+ MY_NAME="ここに自分のTwitterのidの@を抜いた形で設定してください" #自身のTwitterのidを設定

中身

中身シェルスクリプトなので、どうということはない

#!/bin/bash

IFS='
'

MY_NAME="own-twitter-id" #自身のTwitterのidを設定
HIT_LIST=$(cat tweet.js |sed -e 's/window.YTD.tweet.part0 = //'|jq -r -c '.[]'|grep "$1")
HIT_COUNT=$(echo "${HIT_LIST}"|wc -l)
COUNT="1"

for RECORD in $HIT_LIST
do
  echo $RECORD
  ID=$(echo $RECORD|grep -o "\"id\":\".*\""|tr ',' '\n'|grep "\"id\":\".*\""|tail -1|awk -F'"' '{print $4}')
  SCREEN_NAME=$(echo $RECORD|grep -o "screen_name\":\".*\","|awk -F'"' '{print $3}')
  if [ -z "$SCREEN_NAME" ]
  then
    SCREEN_NAME=$MY_NAME
  fi
  echo "https://twitter.com/${SCREEN_NAME}/status/${ID}"
  if [ "$HIT_COUNT" -gt 1 ]
  then
    echo "-------------------- [$HIT_COUNT] --------------------"
    : $((HIT_COUNT--))
  fi
done

使い方

tweet.jsが同じディレクトリにある状態で、引数に検索した文字を入れるだけ
複数件あると複数件ひっかかる
該当のJSONとURLを出力する

$ ./OwnTweetSearch.sh 私見
{"retweeted":false,"source":"<a href=\"http://www.twitpane.com\" rel=\"nofollow\">TwitPanePlus</a>","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"display_text_range":["0","161"],"favorite_count":"32","in_reply_to_status_id_str":"1121753187784876032","id_str":"1121772687645237249","in_reply_to_user_id":"983655865474363392","truncated":false,"retweet_count":"9","id":"1121772687645237249","in_reply_to_status_id":"1121753187784876032","created_at":"Fri Apr 26 13:47:04 +0000 2019","favorited":false,"full_text":"@urbsxb4mu 私見でございますが…以下を順番に読むといい気がしております\n\n入門UNIXシェルプログラミング―シェルの基礎から学ぶUNIXの世界  ブルース・ブリン  (著)\nシェルプログラミング実用テクニック Kindle版 上田隆一  (著)\n\nワイ、入門シェルプログラミングの本でシェルスクリプトを覚(文字数","lang":"ja","in_reply_to_screen_name":"44GG44KT44GT","in_reply_to_user_id_str":"983655865474363392"}
https://twitter.com/44GG44KT44GT/status/1121772687645237249

$ ./OwnTweetSearch.sh 変態だ
{"retweeted":false,"source":"<a href=\"https://about.twitter.com/products/tweetdeck\" rel=\"nofollow\">TweetDeck</a>","entities":{"hashtags":[],"symbols":[],"user_mentions":[{"name":"シェル芸bot","screen_name":"minyoruminyon","indices":["3","17"],"id_str":"3978626952","id":"3978626952"}],"urls":[{"url":"https://t.co/hgjICWlvJF","expanded_url":"https://youtu.be/3OSJlfPag4A","display_url":"youtu.be/3OSJlfPag4A","indices":["36","59"]},{"url":"https://t.co/L8UwU6aKef","expanded_url":"https://twitter.com/yami_buta/status/1121942576657879040","display_url":"twitter.com/yami_buta/stat…","indices":["64","87"]}]},"display_text_range":["0","87"],"favorite_count":"0","id_str":"1121942740575461376","truncated":false,"retweet_count":"0","id":"1121942740575461376","possibly_sensitive":false,"created_at":"Sat Apr 27 01:02:48 +0000 2019","favorited":false,"full_text":"RT @minyoruminyon: 仮に変態だとしても変態という名の https://t.co/hgjICWlvJF だよ! https://t.co/L8UwU6aKef","lang":"ja"}
https://twitter.com/minyoruminyon/status/1121942740575461376
-------------------- [5] --------------------
{"retweeted":false,"source":"<a href=\"http://www.twitpane.com\" rel=\"nofollow\">TwitPanePlus</a>","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"display_text_range":["0","5"],"favorite_count":"1","id_str":"1012308409654231042","truncated":false,"retweet_count":"0","id":"1012308409654231042","created_at":"Thu Jun 28 12:15:07 +0000 2018","favorited":false,"full_text":"変態だった","lang":"ja"}
https://twitter.com/kanata201612/status/1012308409654231042
-------------------- [4] --------------------
{"retweeted":false,"source":"<a href=\"http://www.twitpane.com\" rel=\"nofollow\">TwitPanePlus</a>","entities":{"hashtags":[],"symbols":[],"user_mentions":[{"name":"","screen_name":"youkanyukari","indices":["3","16"],"id_str":"-1","id":"-1"}],"urls":[]},"display_text_range":["0","42"],"favorite_count":"0","id_str":"982603281049403394","truncated":false,"retweet_count":"0","id":"982603281049403394","created_at":"Sat Apr 07 12:57:32 +0000 2018","favorited":false,"full_text":"RT @youkanyukari: 超・記号オンリー難読化シェル芸 とか変態だ・・・","lang":"ja"}
https://twitter.com/youkanyukari/status/982603281049403394
-------------------- [3] --------------------
{"retweeted":false,"source":"<a href=\"http://www.twitpane.com\" rel=\"nofollow\">TwitPanePlus</a>","entities":{"hashtags":[],"symbols":[],"user_mentions":[{"name":"上田 隆一","screen_name":"ryuichiueda","indices":["3","15"],"id_str":"372780389","id":"372780389"}],"urls":[]},"display_text_range":["0","80"],"favorite_count":"0","id_str":"908140256137854976","truncated":false,"retweet_count":"0","id":"908140256137854976","created_at":"Thu Sep 14 01:28:04 +0000 2017","favorited":false,"full_text":"RT @ryuichiueda: 創造し続けようと思う人間には、変態しかあり得ない。人生は変態であり、変態だ。('シェル芸おじさん自叙伝 Ⅱ' p114514)","lang":"ja"}
https://twitter.com/ryuichiueda/status/908140256137854976
-------------------- [2] --------------------
{"retweeted":false,"source":"<a href=\"https://mobile.twitter.com\" rel=\"nofollow\">Twitter Web App</a>","entities":{"hashtags":[],"symbols":[],"user_mentions":[],"urls":[]},"display_text_range":["0","66"],"favorite_count":"6","id_str":"1183283246122946560","truncated":false,"retweet_count":"0","id":"1183283246122946560","created_at":"Sun Oct 13 07:28:04 +0000 2019","favorited":false,"full_text":"着圧ソックスが低気圧時の頭痛に効くっていうから物色してたんだけど、女性用しかないな。これを着ける…?変態じゃないか…(変態だけど…)","lang":"ja"}
https://twitter.com/kanata201612/status/1183283246122946560


Comments

Add picture from clipboard (Maximum size: 100 MB)