Skip to content

Instantly share code, notes, and snippets.

@jaredmichaelwilliams
Last active September 17, 2015 19:17
Show Gist options
  • Select an option

  • Save jaredmichaelwilliams/9b75f9e110cecad49db8 to your computer and use it in GitHub Desktop.

Select an option

Save jaredmichaelwilliams/9b75f9e110cecad49db8 to your computer and use it in GitHub Desktop.

Revisions

  1. Jared Williams revised this gist Sep 17, 2015. 2 changed files with 4 additions and 1 deletion.
    3 changes: 3 additions & 0 deletions Notes
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Dependencies

    brew install gnu-sed
    2 changes: 1 addition & 1 deletion PassScrape.sh
    Original file line number Diff line number Diff line change
    @@ -78,7 +78,7 @@ wordOut=0

    while [ $wordOut -lt 10 ]; do
    WIKPAGE=`curl -Ls https://en.wikipedia.org/wiki/Special:Random | /usr/local/opt/gnu-sed/libexec/gnubin/sed '/</ {:k s/<[^>]*>//g; /</ {N; bk}}' | sed -e '/^$/d' | sort | sed '/.\{10\}/d' | sed -e "/[0-9]/d" | sed '/^..$/d' | sed '/^.$/d' | awk '{print $1}' | grep -E '[:alnum:]' | egrep -v '^$|Tools|{|}'`
    PW[$wordOut]=`echo $WIKPAGE | awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }' | sed -e "s/ /\n/g" | awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }'`
    PW[$wordOut]=`echo $WIKPAGE | awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }' | perl -pe "s/ /\n/g" | awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }'`
    wordOut=`echo $wordOut + 1 | bc`
    done
    echo -e "\n"
  2. Jared Williams created this gist Sep 17, 2015.
    87 changes: 87 additions & 0 deletions PassScrape.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,87 @@
    #!/bin/bash

    # Author: Jared Williams

    function _spinner() {
    # $1 start/stop
    #
    # on start: $2 display message
    # on stop : $2 process exit status
    # $3 spinner function pid (supplied from stop_spinner)

    local on_success="DONE"
    local on_fail="FAIL"
    local white="\e[1;37m"
    local green="\e[1;32m"
    local red="\e[1;31m"
    local nc="\e[0m"

    case $1 in
    start)
    # calculate the column where spinner and status msg will be displayed
    #let column=$(tput cols)-${#2}-8
    let column=1
    # display message and position the cursor in $column column
    echo -ne ${2}
    printf "%${column}s"

    # start spinner
    i=1
    sp='\|/-'
    delay=0.15

    while :
    do
    printf "\b${sp:i++%${#sp}:1}"
    sleep $delay
    done
    ;;
    stop)
    if [[ -z ${3} ]]; then
    echo "spinner is not running.."
    exit 1
    fi

    kill $3 > /dev/null 2>&1

    # inform the user uppon success or failure
    if [[ $2 -eq 0 ]]; then
    echo -en "${on_success}"
    else
    echo -en "${on_fail}"
    fi
    ;;
    *)
    echo "invalid argument, try {start/stop}"
    exit 1
    ;;
    esac
    }

    function start_spinner {
    # $1 : msg to display
    _spinner "start" "${1}" &
    # set global spinner pid
    _sp_pid=$!
    # disown
    }

    function stop_spinner {
    # $1 : command exit status
    _spinner "stop" $1 $_sp_pid
    unset _sp_pid
    }

    start_spinner "Scraping Data. This may take a minute."

    wordOut=0

    while [ $wordOut -lt 10 ]; do
    WIKPAGE=`curl -Ls https://en.wikipedia.org/wiki/Special:Random | /usr/local/opt/gnu-sed/libexec/gnubin/sed '/</ {:k s/<[^>]*>//g; /</ {N; bk}}' | sed -e '/^$/d' | sort | sed '/.\{10\}/d' | sed -e "/[0-9]/d" | sed '/^..$/d' | sed '/^.$/d' | awk '{print $1}' | grep -E '[:alnum:]' | egrep -v '^$|Tools|{|}'`
    PW[$wordOut]=`echo $WIKPAGE | awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }' | sed -e "s/ /\n/g" | awk 'BEGIN { srand() } int(rand() * NR) == 0 { x = $0 } END { print x }'`
    wordOut=`echo $wordOut + 1 | bc`
    done
    echo -e "\n"
    echo ${PW[*]}
    echo -e "\n"
    stop_spinner $?