Sha256: 32397336f3a8871eb4bccaf118ceb292f49ea2718d01a22c8beeff0e9f1559b7

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# Get twitter status for given account (or for the default one, "sencha")

page = require('webpage').create()
twitterId = 'sencha' #< default value

# 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
if phantom.args.length < 1
    console.log 'Usage: tweets.coffee [twitter ID]'
else
    twitterId = phantom.args[0]

# 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, ''}"
    phantom.exit()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phantomjs.rb-0.0.2 vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee
phantomjs.rb-0.0.1 vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee