TwitterSearch.sh

TwitterSearch ver 0.3 - kanata, 11/27/2016 01:08 PM

Download (1.61 KB)

 
1
#!/bin/bash
2

    
3
# TwitterSearch ver 0.3
4
# 2016.11.27 kanata
5
# option -noimage 画像表示をしない
6
#
7
# こんな感じで監視できる
8
# watch -n 10 -c -d TwitterSearch.sh '地震' -noimage
9

    
10
SEARCH_WORD=`ruby -r cgi -e "puts CGI.escape(\""$1"\")"`
11

    
12
TEMP="/tmp/TwitterSearch_temp_$$"
13

    
14
IFS='
15
'
16

    
17
CONTENT=`curl -s "http://twinavi.jp/twitter/search/?q=${SEARCH_WORD}&or=1&ob=1"|grep -e 'twitter-search-result-name' -e 'twitter-search-result-text' -e 'twitter-search-image'|sed -e 's/^ *//g'|grep  -v 'twitter-search-imagebox.*colorbox'`
18

    
19
mkdir -p ${TEMP}
20
trap 'rm -rf ${TEMP}; exit 1' 1 2 3 11 15
21

    
22
for LINE in $CONTENT
23
do
24
  if   echo $LINE | grep twitter-search-result-name >/dev/null
25
  then
26
    echo -e "\e[1m" 
27
    echo "${LINE}" |  sed -e 's/<[^>]*>//g'
28
    rm -f ${TEMP}/*
29
  elif echo $LINE | grep twitter-search-result-text >/dev/null
30
  then
31
    printf "\e[0m"
32
    echo "  ${LINE}" |  sed -e 's/<[^>]*>//g'
33
    rm -f ${TEMP}/*
34
  elif echo $LINE | grep twitter-search-image >/dev/null
35
  then
36
    #if [ `echo "${@}" | grep 'noimage' >/dev/null` -a ! -z "`ls -A ${TEMP}`" ]
37
    #if [ ! `echo "${@}" | grep 'noimage' >/dev/null` ]
38
    if ! echo "${@}" | grep 'noimage' >/dev/null
39
    then
40
    if [ -z "`ls -A ${TEMP}`" ]
41
    then
42
      IMAGE_URL=`echo ${LINE} |sed 's/http/\nhttp/g'|tail -1|awk '{print $1}'|tr -d '"'`
43
      wget -nv ${IMAGE_URL} -P ${TEMP} 2>/dev/null
44
      wait
45
      for WORD in `ls ${TEMP}`
46
      do
47
        convert ${TEMP}/${WORD} -interlace none ${TEMP}/converted_${WORD}
48
      done
49
      echo ${IMAGE_URL}
50
      test -x `which cam` && cam ${TEMP}/converted_*
51
    fi
52
    fi
53
  else
54
    :
55
  fi
56

    
57
done
58

    
59
rm -rf ${TEMP}
60

    
61
exit 0
Add picture from clipboard (Maximum size: 100 MB)