2012-03-13 08:35:40 +04:00
|
|
|
# Get twitter status for given account (or for the default one, "HeadlessPhantom")
|
2011-06-02 10:15:54 +04:00
|
|
|
|
2011-09-13 00:17:54 +04:00
|
|
|
page = require('webpage').create()
|
2012-01-14 19:13:26 +04:00
|
|
|
system = require 'system'
|
2012-03-13 08:35:40 +04:00
|
|
|
twitterId = 'HeadlessPhantom' #< default value
|
2011-06-02 10:15:54 +04:00
|
|
|
|
|
|
|
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
|
|
page.onConsoleMessage = (msg) ->
|
|
|
|
console.log msg
|
|
|
|
|
|
|
|
# Print usage message, if no twitter ID is passed
|
2012-01-14 19:13:26 +04:00
|
|
|
if system.args.length < 2
|
2011-06-02 10:15:54 +04:00
|
|
|
console.log 'Usage: tweets.coffee [twitter ID]'
|
2011-03-02 11:41:23 +03:00
|
|
|
else
|
2012-01-14 19:13:26 +04:00
|
|
|
twitterId = system.args[1]
|
2011-06-02 10:15:54 +04:00
|
|
|
|
|
|
|
# Heading
|
|
|
|
console.log "*** Latest tweets from @#{twitterId} ***\n"
|
|
|
|
|
|
|
|
# Open Twitter Mobile and, onPageLoad, do...
|
|
|
|
page.open encodeURI("http://mobile.twitter.com/#{twitterId}"), (status) ->
|
|
|
|
# Check for page load success
|
|
|
|
if status isnt 'success'
|
|
|
|
console.log 'Unable to access network'
|
|
|
|
else
|
|
|
|
# Execute some DOM inspection within the page context
|
|
|
|
page.evaluate ->
|
|
|
|
list = document.querySelectorAll 'span.status'
|
|
|
|
for i, j in list
|
|
|
|
console.log "#{j + 1}: #{i.innerHTML.replace /<.*?>/g, ''}"
|
2011-03-02 11:41:23 +03:00
|
|
|
phantom.exit()
|