#!/bin/sh sweep(){ # clear old data/prepare for first run rm -rf temp mkdir temp } sweep # retrieve filtered LMR shoutbox data and separate shouts into individual files (cut.1, cut.1, etc) in the temp directory get_html(){ nmbr=1 # used in cut file filenames python sbx.py # run python script to get data awk '{f = "temp/cut." NR; print $0 > f; close(f)}' filtered # splits master file into separate numbered files at new lines } get_html make_page(){ troff -a temp/cut.$nmbr > temp/cut_f2 # convert Nroff format text to ASCII text sed 1d temp/cut_f2 > temp/cut_f3 # first line is garbage; cut it out of file if [ $nmbr -eq 1 ] ; then #first cut has leading characters to remove #FILENAME=temp/cut_f3 # measure byte size #FILESIZE=$(stat -c%s "$FILENAME") cut -c 13-$FILESIZE temp/cut_f3 > temp/page_t # trim from name start to end of file else rm temp/page_t # subsequent shouts only have the first garbage line mv temp/cut_f3 temp/page_t fi page=`cat temp/page_t` } make_page # copy processed shout file into string variable load_var(){ raw_code=`cat temp/page_t` } load_var # remove starter filler. # An individual's shout is easy to isolate from the others and they all have the same structure: # Username: Shout # The colon will be used as the cutting point to separate the username from the shout itself get_username(){ # isolate username echo `expr index "$raw_code" : ` > temp/pos.txt # get position of char : (directly follows username) and save to file pos=`cat temp/pos.txt` # load : position from file to variable name_end=$(($pos + 1)) # adjusts variable value to use in setting username ending byte position cut -c 1-$name_end temp/page_t > username.txt # trim username with colon from body and save to txt #echo $username # debug } get_shout(){ # isolate shout cut -c $name_end-$FILESIZE temp/page_t > shout.txt # trims username from shout and saves shout txt file. } get_username marker=/:/ # convert ":" to "says" c2says(){ sed -i 's/:/ says/g' username.txt } get_shout c2says # load username and shout data on files into variables for further processing load_data(){ username=`cat username.txt` shout=`cat shout.txt` # echo "$username" # echo "$shout" } load_data speak_username(){ espeak -ven/en-us -s 120 -f username.txt --stdout|aplay # pipe to aplay prevents "stuttering" } speak_shout(){ espeak -ven/en-us -s 120 -f shout.txt --stdout|aplay } speak_username speak_shout # save current data to archive files save_data(){ # echo $username > username_old.txt # echo $shout > shout_old.txt rm temp/bookmark_t cp temp/page_t temp/bookmark_t bookmark=`cat temp/bookmark_t` } save_data say_it(){ save_data load_var get_username get_shout c2says load_data speak_username speak_shout } sleep 20 # loop begins here <---------------- if [ -t 0 ]; then stty -echo -icanon time 0 min 0; fi count=0 keypress='' while [ "x$keypress" = "x" ]; do count=$(($count+1)) get_html make_page # compare first new shout with the last shout spoken if diff temp/page_t temp/bookmark_t >/dev/null ; then # same sleep 1 else # different while [ true ] # loop until index = 1 do if diff temp/page_t temp/bookmark_t >/dev/null ; then # same nmbr=$(($nmbr-1)) # decrement cut file index to oldest new shout file make_page # reload shout data say_it # plays the shout else # different nmbr=$(($nmbr+1)) # index next older shout file make_page # create new file for next comparison fi if test $nmbr -eq 1 # if cut file 1 has played then break # exit loop fi done fi sleep 20 read keypress # exits loop upon any keypress done if [ -t 0 ]; then stty sane; fi echo "You pressed '$keypress' to stop this script after $count loop iterations" exit 0