Skip to content

Instantly share code, notes, and snippets.

@ypoluektovich
Last active January 3, 2016 12:48
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 ypoluektovich/8464955 to your computer and use it in GitHub Desktop.
Save ypoluektovich/8464955 to your computer and use it in GitHub Desktop.
List rolls from invisiblecastle.com
#!/bin/bash
tehStart=0
tehEnd=0
LSIC_SPREAD=${LSIC_SPREAD:-50}
case "$#" in
"0" )
cat <<EOF
Usage:
$0 <center index>
or:
$0 <start index> <end index>
Will print an html table of invisiblecastle rolls to standard output.
First variant prints rolls with the specified index, +- ${LSIC_SPREAD};
second variant prints rolls in the specified range (feeds args to seq).
Spread can be controlled by setting variable LSIC_SPREAD.
You can control the host part of fetched IC URLs by setting LSIC_HOST.
EOF
exit 0
;;
"1" )
tehStart=$(($1 - $LSIC_SPREAD))
tehEnd=$(($1 + $LSIC_SPREAD))
;;
"2" )
tehStart="$1"
tehEnd="$2"
;;
* )
echo "Specify one (+/- $LSIC_SPREAD) or two (range) roll ids" 1>&2
echo "(or run without arguments for usage help)" 1>&2
exit 1
;;
esac
tehTmp=$(mktemp)
echo "Using temp file $tehTmp" 1>&2
echo "Using host ${LSIC_HOST:=invisiblecastle.com}" 1>&2
echo "<html>"
echo "<head><style type=\"text/css\">table,tr,td{border:1px solid black;}</style></head>"
echo "<body><table>"
for ix in $( seq $tehStart $tehEnd ); do
echo "<tr><td><a href=\"http://invisiblecastle.com/roller/view/$ix/\">$ix</a></td>"
wget "http://$LSIC_HOST/roller/view/$ix/" --header="Host: invisiblecastle.com" -O "$tehTmp" -nv
tehTitle=$( grep "<h2>" "$tehTmp" | sed -r "s!<h2>Die roll for (.*)</h2>!\1!" )
tehDate=$( grep 'class="date"' "$tehTmp" | sed -r 's!^.*Rolled on: (.*)</p>$!\1!' )
tehResult=$( grep 'class="dice"' "$tehTmp" | sed -r 's!^<span class="dice">(.*)</span>(.*)<.*[0-9]">(.*)</span>$!\1\2\3!' )
echo "<td>$tehTitle</td><td>$tehDate</td><td>$tehResult</td>"
echo "</tr>"
done
echo "</table></body></html>"
rm "$tehTmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment