1 # Get twitter status for given account (or for the default one, "PhantomJS")
3 page = require('webpage').create()
4 system = require 'system'
5 twitterId = 'PhantomJS' #< default value
7 # Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
8 page.onConsoleMessage = (msg) ->
11 # Print usage message, if no twitter ID is passed
12 if system.args.length < 2
13 console.log 'Usage: tweets.coffee [twitter ID]'
15 twitterId = system.args[1]
18 console.log "*** Latest tweets from @#{twitterId} ***\n"
20 # Open Twitter Mobile and, onPageLoad, do...
21 page.open encodeURI("http://mobile.twitter.com/#{twitterId}"), (status) ->
22 # Check for page load success
23 if status isnt 'success'
24 console.log 'Unable to access network'
26 # Execute some DOM inspection within the page context
28 list = document.querySelectorAll 'div.tweet-text'
30 console.log "#{j + 1}: #{i.innerText}"