Google Trends Script

2013.09.23   11:37AM   programming

Recently I tried out GeekTool (a Mac version of Linux's Conky) and I am quite impressed! Right now I have scripts on my desktop that show the time, weather, unread emails, network stats and laptop stats. And I just threw together a script of my own:

#!/bin/sh

rm ./spicy.txt

url='http://www.google.com/trends/hottrends/atom/hourly'

echo "      -- SPICY GOOGLE SEARCHES --"
curl --silent "$url" | grep "Spicy" | sed -n -e 's/.*">\(.*\)<\/a>.*/\1/p' >> ./spicy.txt
while read p; do
    echo $p
    sleep $[ ( $RANDOM % 14 ) + 1 ]s
    echo "    (" | tr -d "\n"
    curl -s --get --data-urlencode "q=wikipedia $p" http://ajax.googleapis.com/ajax/services/search/web?v=1.0 | \
        egrep -o 'is a.........................|was a........................' | \
        head -n1 | tr -d '\n' && echo "...)"
done < ./spicy.txt		

This script pulls the hour's hottest google search terms, and then gets a short description from wikipedia. You should note that running this script very often will result in curl not working (Google's servers will start blocking your address). The random sleep helps to prevent this. You can download the script here. Feel free to use this script for your own Bash adventures. Happy coding!

by Chris McComb

LXN

Home

Recent

Tags

Archive


Google+

RSS Feed

© Chris McComb 2013