Skip to content

Instantly share code, notes, and snippets.

@kobalab
Last active January 28, 2024 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobalab/16b86e210df3624f8a409d210fec5d2c to your computer and use it in GitHub Desktop.
Save kobalab/16b86e210df3624f8a409d210fec5d2c to your computer and use it in GitHub Desktop.
天鳳の鳳凰卓の牌譜をすべて電脳麻将形式に変換する
#!/bin/sh
#
# tenhou-log-all - 天鳳鳳凰卓(東南戦)の牌譜を電脳麻将形式で全て取得する
#
# - tenhou-log-all
# 最新(昨年分)の牌譜が公開されたかチェックする
# - tenhou-log-all workdir
# 昨年分の牌譜を電脳麻将形式に変換して workdir に取得する
# - tenhou-log-all workdir year
# year で指定した年の牌譜を電脳麻将形式に変換して workdir に取得する
set -e
PATH=$PATH:/usr/local/bin
export PATH
tenhou-log --version > /dev/null
workdir=$1
test $2 && year=$2 || year=`expr \`date +%Y\` - 1`
curl -Ls https://tenhou.net/sc/raw/ | grep scraw$year.zip > /dev/null \
&& exist=1 || true
if [ ! $exist ]
then
[ $workdir ] && echo $year not exists
exit 1
fi
[ ! $workdir ] && echo $year FOUND !! && exit
test -d $workdir || mkdir $workdir
cd $workdir
[ -d $year ] && ( echo $year already exists; exit 1 )
[ -d IN ] || [ -d OUT ] && ( echo Running...; exit 1 )
mkdir IN OUT
cd IN
curl -Lfs https://tenhou.net/sc/raw/scraw$year.zip > scraw$year.zip
unzip scraw$year.zip > /dev/null 2>&1
ls $year/scc* > /dev/null
for file in $year/scc*
do
test $year -lt 2013 && cat $file || gunzip -c $file
done |\
grep ' 四鳳南喰赤' |\
sed 's/^.*log=//' | sed 's/".*$//' > ../OUT/index.txt
cd ..
rm -rf IN
cd OUT
for id in `cat index.txt`
do
tenhou-log $id > $id.json && gzip $id.json || rm $id.json
done
cd ..
mv OUT $year
echo "**** $year DONE !! ****"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment