Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / phantomjs / lib / phantom / examples / tweets.coffee
1 # Get twitter status for given account (or for the default one, "PhantomJS")
2
3 page = require('webpage').create()
4 system = require 'system'
5 twitterId = 'PhantomJS' #< default value
6
7 # Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
8 page.onConsoleMessage = (msg) ->
9   console.log msg
10
11 # Print usage message, if no twitter ID is passed
12 if system.args.length < 2
13   console.log 'Usage: tweets.coffee [twitter ID]'
14 else
15   twitterId = system.args[1]
16
17 # Heading
18 console.log "*** Latest tweets from @#{twitterId} ***\n"
19
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'
25   else
26     # Execute some DOM inspection within the page context
27     page.evaluate ->
28       list = document.querySelectorAll 'div.tweet-text'
29       for i, j in list
30         console.log "#{j + 1}: #{i.innerText}"
31   phantom.exit()