cephurs icon

nachash's Big Fucking Twitter Gun

cephurs | PRO | 11/08/14 05:12:01 AM UTC | 0 ⭐ | 1093 👁️ | Never ⏰ | []
Bash |

4.72 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
now=$(date +"%Y_%m_%d_-_%H_%M_%S" ) # Just setting the date and time
 
echo "Now pointing the BFTG-9000 at $1"
gzip -d ~/dox/twitter/timelines/$1.gz 2> /dev/null
usewithtor /usr/local/bin/twitter-archiver -o -f -s ~/dox/twitter/timelines $1
gzip ~/dox/twitter/timelines/$1 2> /dev/null
 
if [ -f ~/dox/twitter/timelines/$1.gz ] || [ -f ~/dox/twitter/timelines/$1 ]; then
 
    echo "Direct hit! Area damage coming in 3... 2... 1..."
 
    # This section pulls the mentions out of the chosen timeline, places them in a
    # file, formats them so that all the names are lowercase, sorts for uniqueness,
    # and finally removes the @ symbols. It also generates a simple report which
    # shows how many times the target mentioned each account, sorted from most to
    # least number of mentions.
 
    gunzip ~/dox/twitter/timelines/$1.gz 2> /dev/null
    grep -Eo ' @[A-Za-z0-9_]+' ~/dox/twitter/timelines/$1 > ~/dox/twitter/mentions/$1-raw
    tr '[:upper:]' '[:lower:]' < ~/dox/twitter/mentions/$1-raw >> ~/dox/twitter/mentions/$1-alpha
    sort ~/dox/twitter/mentions/$1-alpha | uniq -c > ~/dox/twitter/mentions/$1-mc-alpha
    awk '{print $2,$1}' ~/dox/twitter/mentions/$1-mc-alpha > ~/dox/twitter/mentions/$1-mc-beta
    sort -grk 2 ~/dox/twitter/mentions/$1-mc-beta > ~/dox/twitter/mentions/$1_mentions_count.txt
    sort -u ~/dox/twitter/mentions/$1-alpha > ~/dox/twitter/mentions/$1.full.txt
    totalMentions=$(wc -l ~/dox/twitter/mentions/$1.full.txt | awk '{print $1}')
    sort -u  ~/dox/twitter/mentions/$1.full.txt >  ~/dox/twitter/mentions/$1-beta
    sed -i 's/ @//g' ~/dox/twitter/mentions/$1-beta
    echo "BOOM! Now for the dust to settle..."
 
    # This section pulverizes the data left over from the previous section to
    # create a shell script which will crawl the accounts you don't already
    # have saved.
 
    ls ~/dox/twitter/timelines/ | sort -u > ~/dox/twitter/ls.txt
    sed -i 's/\.gz//'g ~/dox/twitter/ls.txt
    comm -13 ~/dox/twitter/ls.txt ~/dox/twitter/mentions/$1-beta > ~/dox/twitter/mentions/$1-rc 2> /dev/null
    uniqueMentions=$(wc -l ~/dox/twitter/mentions/$1-rc | awk '{print $1}')
    sed -i -e 's/^/~\/twit.sh /' ~/dox/twitter/mentions/$1-rc
    echo '#!/bin/bash' | cat - ~/dox/twitter/mentions/$1-rc > ~/dox/twitter/mentions/$1-rc.temp
    mv ~/dox/twitter/mentions/$1-rc.temp ~/dox/twitter/mentions_scripts/$1.sh
    #sed '0~11 s/$/\nsleep 900/g' < ~/dox/twitter/mentions/$1-rc > ~/dox/twitter/mentions_scripts/$1.sh # Seems to not be required anymore
    chmod +x ~/dox/twitter/mentions_scripts/$1.sh
    echo "OUCH! Nothing left but their shoes. You have to crawl $uniqueMentions out of $totalMentions accounts. $1 status: demolished, will not recover, etc."
    #rm -rf ~/dox/twitter/mentions/$1-*
    gzip ~/dox/twitter/timelines/$1 2> /dev/null
    echo "Timeline: ~/dox/twitter/timelines/$1"
    echo "Mentions script: ~/dox/twitter/mentions_scripts/$1.sh"
    echo "Time analysis: ~/dox/twitter/times/$1_$now.txt"
 
else
 
    echo "Oh, fail."
 
fi
 
if [ -f ~/dox/twitter/timelines/$1 ]; then
 
    # The section will pull the timestamps from the last 200 tweets, then sort by
    # hour, and tell us how many times the target tweeted during each hour.
 
    echo "###########################################################################" > ~/dox/twitter/times/$1_$now.txt
    echo "# Hours/tweets for $1's last 200 tweets" >> ~/dox/twitter/times/$1_$now.txt
    echo "###########################################################################" >> ~/dox/twitter/times/$1_$now.txt
 
    tail -n 200 ~/dox/twitter/timelines/$1 > ~/dox/twitter/times/$1-tail
    awk '{print $3}' ~/dox/twitter/times/$1-tail > ~/dox/twitter/times/$1-tail-raw
    sed -i 's/:/ /g' ~/dox/twitter/times/$1-tail-raw
    awk '{print $1}' ~/dox/twitter/times/$1-tail-raw > ~/dox/twitter/times/$1-tail-beta
    sort ~/dox/twitter/times/$1-tail-beta | uniq -c | awk '{print $2,$1}' >> ~/dox/twitter/times/$1_$now.txt
 
    # This section does the same as the previous section, except it acts upon
    # the entire collected timeline.
 
    echo "###########################################################################" >> ~/dox/twitter/times/$1_$now.txt
    echo "# Hours/tweets for all of $1's stored tweets" >> ~/dox/twitter/times/$1_$now.txt
    echo "###########################################################################" >> ~/dox/twitter/times/$1_$now.txt
 
    awk '{print $3}' ~/dox/twitter/timelines/$1 > ~/dox/twitter/times/$1-raw
    sed -i 's/:/ /g' ~/dox/twitter/times/$1-raw
    awk '{print $1}' ~/dox/twitter/times/$1-raw > ~/dox/twitter/times/$1-beta
    sort ~/dox/twitter/times/$1-beta | uniq -c | awk '{print $2,$1}' >> ~/dox/twitter/times/$1_$now.txt
    rm -rf ~/dox/twitter/times/$1-*
fi

Comments