Skip to content
fczuardi edited this page Aug 24, 2010 · 11 revisions

Examples

This is a collection of some of the neat things you can achieve by combining the Trending Topics Client with other UNIX utilities.

Just open a terminal window and paste the code snippets below to run them.

Display only the top 5 trending topics

node ttc.js |grep -e"^[1-5]\. "

or

node ttc.js -f names|head -n 5

Display only the numbered names…

…by removing the urls of the normal view

node ttc.js | sed s/.-.http.*//

…by adding line numbers to the names view

node ttc.js -f names | head -n 10 | nl -s ". "

Quick find the woeid code for São Paulo in the help page

node ttc.js --help | grep Paulo

Save the output results to a file…

…Overwriting

mkfifo pipe1
node ttc.js -f json --location mx > pipe1 & cat pipe1 > output.json

…Appending

mkfifo pipe1
node ttc.js -f json --location mx > pipe1 & cat pipe1 >> output.json

Save the results to a file with the timestamp as the filename

node ttc.js --location mx > pipe1 & cat pipe1 >`date +%s`.log

Append the results of São Paulo's Trending topics to a log file every 5 minutes

while [ 0 ]; do node ttc.js -l 455827 | tail -n 17 >> sptrends.log; sleep 300; done;

Compare Brazil and São Paulo side by side

mkfifo pipe1 pipe2
node ttc.js -l br > pipe1 & node ttc.js -l 455827 > pipe2 & diff -y pipe1 pipe2

What Brazil and São Paulo have in common

node ttc.js -f names -l br > pipe1 & node ttc.js -f names -l 455827 > pipe2 & perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/'  pipe1 pipe2

(credit: http://www.cyberciti.biz/faq/command-to-display-lines-common-in-files/ )

Notification (MacOSX + growlnotify)

Just the list

node ttc.js -f names | head -n 10 | nl -s ". " | growlnotify --title "Trending Topics"

The list with location, time and remaining API calls

node ttc.js | tail -n 15 | sed s/.-.http.*// | growlnotify

Notify Brazilian Trending Topics every 5 minutes

while [ 0 ]; do node ttc.js -l br | tail -n 15 | sed s/.-.http.*// | growlnotify --title "Trending Topics"; sleep 300; done;