単語帳データベースの修正

発音記号を中心として修正項目が大量に発生したので、ソフトを急拵えしました。

dbedit.sh のリスト

#!/bin/bash
host=xxx.xxx.xxx.xxx
db=xxxxx

while :
do

temp=`mktemp ./XXXX`
db_line=`\
mysql -h ${host} ${db} -N << _SQL_
 select id,memo,seq from correct where seq=
  ( select min(seq) from correct where !settled);
_SQL_`

id=`echo ${db_line} | awk '{print $1}'`
echo ${db_line} | awk '{printf "\033[0;32m%s\033[0;39m\n",$2}'
mysql -h ${host} ${db} -N <<_SQL_ | tee ${temp}
 select id from vocabulary where id=${id};
 select ch from vocabulary where id=${id};
 select py from vocabulary where id=${id};
 select ja from vocabulary where id=${id};
_SQL_
seq=`echo ${db_line} | awk '{print $3}'`

 while :
 do
  printf "\n ---------------------------------   \n"
  printf "エディットする場合は e を押して下さい。\n"
  printf "承認する場合は a を押して下さい。\n"
  nonewline "終了する場合は q を押して下さい。 "
  read RESP
  char=`echo $RESP | cut -c1`
  case $char in
  e|E) 
   gedit ${temp}
   ./updateDB file=${temp}
   break;;
  a|A) 
   mysql -h ${host} ${db} -N <<_SQL_
    update correct set settled=true where seq=${seq};
_SQL_
   break;;
  q|Q)
   rm ${temp}
   exit 0;
   break;;
  ?) echo "もう一度お願いします" ;;
  esac
 done

rm ${temp}
done    

updateDB のリスト

#! /bin/bash
ctlfile=`getparstr $# "$*" "file"`
logfile="correct_DB.log"
host=xxx.xxx.xxx.xxx
DB=xxxxx
id=`cat $ctlfile |\ awk 'NR==1{print $0}'` ch=`cat $ctlfile |\ awk 'NR==2{print $0}'` py=`cat $ctlfile |\ awk 'NR==3{print $0}'` ja=`cat $ctlfile |\ awk 'NR==4{print $0}'` # 谷歌翻译から ${ch} の音声データをダウンロードしBASE64エンコードする # ダウンロードにあたっては http://healingk.blog72.fc2.com/blog-entry-63.html を参考にしました mp3file="download_voice.mp3" agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0" wget --user-agent="${agent}" \ --quiet \ "http://translate.google.com/translate_tts?tl=zh-ch&q="${ch}"&client=tw-ob" \ -O ${mp3file} mplayer ${mp3file} >/dev/null 2>&1 voice=`base64 -w0 ${mp3file}` rm ${mp3file} # 汉语,拼音,日本語訳,BASE64エンコードした音声をデータベース更新する mysql -N -h ${host} ${DB} << _SQL_ >> ${logfile} update vocabulary set ch="${ch}",py="${py}", ja="${ja}",voice="${voice}" where id=${id}; _SQL_

プロンプトに Edit と回答するとテキストエディターが起動します。修正を実施してテキストエディターを終了すると、./updateDB に処理が移行しデータベースの update を行います。修正をテキストエディターに依存するようにした点が、优点でもあり缺点とも言えます。