Skip to content

Instantly share code, notes, and snippets.

@nyaocat
Created August 16, 2014 07:51
Show Gist options
  • Save nyaocat/c4d116562e58c3e6129c to your computer and use it in GitHub Desktop.
Save nyaocat/c4d116562e58c3e6129c to your computer and use it in GitHub Desktop.
#!/usr/local/bin/bash
export PATH=/home/nyaocat/bin:/usr/local/bin/:$PATH
export LANG=ja_JP.utf-8
if [ $HTTP_HOST$REQUEST_URI != kenkov.nyaocat.jp/ ]
then
echo "Location: http://kenkov.nyaocat.jp/"
echo
exit
fi
function escape() {
sed -e 's/</</g' -e 's/>/>/g' -e 's/"/”/g' -e "s/'/’/g" -e 's/&/&/g' -e 's/(/(/g' -e 's/)/)/g'
}
function tozen() {
zen -d "$(cat /dev/stdin)"
}
function joshi() {
nkf -e | mecab -F"%m,%H\n" -E "" | nkf -w8 | while read line
do
L=$(cut -d',' -f 1 <<< $line)
R=$(cut -d',' -f 2- <<< $line)
if echo $R | grep -q -F '終助詞'
then
if echo 'えけせてねへめえれえ' | grep -q -F "$L"
then
printf "%sぇっ" $L
elif echo 'おこそとのほもよろを' | grep -q -F "$L"
then
printf "%sぉっ" $L
else
printf "%sっ" $L
fi
elif echo $R | grep -q -F '助詞'
then
printf "%sっ" $L
elif echo $R | grep -q -F '句点'
then
printf "っ " $L
elif echo $R | grep -q -F '接尾,人名'
then
printf "たん"
elif echo $R | grep -q -F 'どきどき'
then
printf "アンアン"
else
printf "%s" $L
fi
done
}
function kenkov() {
if [ $(($RANDOM%100)) -gt 90 -o $CONTENT_LENGTH -le 20 ]
then
echo "アンッ!アンッ!アンッ!アンッ!"
exit
fi
joshi |
nkf -x -Z4 -w8 |
tozen |
sed 's/っっ/っ/g' |
sed 's/+/ /g' |
sed -e 's/ド/ヨ/g' |
sed -e 's/ト/ヨ/g'
}
if [ $REQUEST_METHOD = POST ]
then
IN=$(cat /dev/stdin)
IN=$(nkf -w8 --url-input <<<${IN:2} | escape)
else
IN="これは@kenkovさんの様なツイートを生成するサービスです.作者はかわいい@nyaocatちゃんです."
fi
cat <<EOF
Content-Type: text/html; charset=utf-8
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<title>こふ語ジェネレーター</title>
<style>
h1 {
display:inline;
}
h1:before {
content: url(http://twiticon.herokuapp.com/kenkov/bigger);
border: 4px solid gray;
border-radius:10px;
margin-right:0.5em;
}
</style>
</head>
<body>
<div class="container">
<div class="page-header">
<a href="/">
<h1>こふ語ジェネレーター</h1>
</a>
<a href="http://b.hatena.ne.jp/entry/http://kenkov.nyaocat.jp/" class="hatena-bookmark-button" data-hatena-bookmark-title="こふ語ジェネレーター" data-hatena-bookmark-layout="simple-balloon" title="このエントリーをはてなブックマークに追加"><img src="http://b.st-hatena.com/images/entry-button/[email protected]" alt="このエントリーをはてなブックマークに追加" width="20" height="20" style="border: none;" /></a><script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8" async="async"></script>
<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
<script>!function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = p + '://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js, fjs);
}
}(document, 'script', 'twitter-wjs');</script>
</div>
<blockquote>
<p class="lead">催眠トランスでっアンッ!アンッ!アンッ!アンッ!</p>
</blockquote>
<p>
</p>
<p><a href="https://twitter.com/intent/user?screen_name=kenkov">@kenkov</a>みたいなツイートを生成するよ.非公認だよ.作者:<a href="https://twitter.com/intent/user?screen_name=nyaocat">@nyaocat</a></p>
<form role="form" class="form-horizontal" method="post" action="/">
<div class="form-group">
<div class="col-lg-10">
<textarea id="b" name="b" cols="80" rows="2" type="text" placeholder="(ココにっ文章をっ入力するんですっ)" class="form-control">$IN</textarea>
</div>
</div>
<div class="form-group">
<div class="col-lg-10">
<button type="submit" class="btn btn-primary btn-block">こふナイズするっ</button>
</div>
</div>
</form>
EOF
if [ $REQUEST_METHOD = POST ]
then
KEKKA=$(kenkov <<< $IN)
cat << EOF
<div class="panel panel-success">
<div class="panel-heading">
<h3>変換けっかっ</h3>
</div>
<div class="panel-body">
<p>
$KEKKA
</p>
<p>
<a href="https://twitter.com/share?text=$KEKKA" class="twitter-share-button" data-lang="ja" data-size="large" data-related="kenkov" data-count="none" data-hashtags="kenkovgen">ツイッヨするっ</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script></p>
</p>
</div>
</div>
EOF
fi
cat << EOF
</div>
</body>
</html>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment