Stock Exchange

Stock Exchange

Most of the firms rely upon Stock Exchange for trade information. They extract information related to latest price from the related web pages. This sample demonstrates the use of IVR to announce the latest stock price by extracting data via web scraping. Since the information in the website is subject to change depending on the market conditions, user should perform HTML parsing updations at regular intervals.

Download the evaluation version of Xtend IVR and install the telephony application in your system. Run the sample script from the Script Editor. Click here to refer the code.

The automated attendant will work as given below:

  • IVR waits for the call
  • Caller dials the number, IVR accepts the call and plays the Welcome message
  • The http() plugin establishes the connection with the website to retrieve the business information
  • IVR extracts the information and speaks out the result
Download the source file zip download for the Internet Application - Stock Exchange

MAIN:
	display "Waiting for call . . ."
	answer 1
	play "welcome.wav"
	wait 0
	
	
	play "music.wav"
	play "music.wav"
	play "music.wav"
	
	
	$stat = http("http://www.amex.com/equities/mktSum/EqMsMostActive.jsp")
	clear
	if $stat != 1
		play "error.wav"
		goto MAIN
	endif	
	
	
	$count = 0
	$str = $http.page
	
	while TRUE


	$index = find($str,"EqLCCmpDesc.jsp")
	if $index == -1
		if $count == 0
			log "The html report format has been changed. 
				Please rework your parsing routines"
			play "down.wav"
			goto BYE
		else
			break
		endif
	endif
	$index += len("EqLCCmpDesc.jsp")
	$str = mid($str,$index)	
	
	$index = find($str,>")
	if $index == -1
		log "The html report format has been changed.
			Please rework your parsing routines"
		play "down.wav"
		goto BYE
	endif
	$index += len(">")
	$str = mid($str,$index)
	
	
	$index = find($str,"</A>")
	if $index == -1
		log "The html report format has been changed.
				Please rework your parsing routines"
		play "down.wav"
		goto BYE
	endif
	
	
	$var = format("$company.%d",$count)
	$$var = mid($str,0,$index)
	
	
	$index += len("</A>")
	$str = mid($str,$index)


	$index = find($str,'"value">')
	if $index == -1
		log "The html report format has been changed.
				Please rework your parsing routines"
		play "down.wav"
		goto BYE
	endif
	$index += len('"value">')
	$str = mid($str,$index)
	
	
	$index = find($str,"</TD>")
	if $index == -1
		log "The html report format has been changed.
				Please rework your parsing routines"
		play "down.wav"
		goto BYE
	endif
	
	
	$var = format("$LastSale.%d",$count)
	$$var = mid($str,0,$index)
	
	
	$index += len("</TD>")
	$str = mid($str,$index)
		

	$index = find($str,"<IMG")
	if $index == -1
		log "The html report format has been changed.
				Please rework your parsing routines"
		play "down.wav"
		goto BYE
	endif
	$temp = mid($str,0,$index)
	
	$flag = ""
	$os = find($temp,'"up">')
	if $os != -1
		$os += len('"up">')
		$flag = "+"
	else
		$os = find($temp,'"down">')
		if $os != -1
			$os += len('"down">')
			$flag = "-"
		endif
	endif
	$temp = mid($temp,$os)
	
	
	$var = format("$NetChange.%d",$count)
	$$var = format("%c%s",$flag,$temp)


	$var1 = format("$company.%d",$count)
	speak "Company, "
	speak $$var1
	
	$var2 = format("$LastSale.%d",$count)
	speak "Last Sale "
	speak $$var2
	
	$var3 = format("$NetChange.%d",$count)
	speak "Net Change "
	speak $$var3
	
	$trace = concat($$var1,".  Last Sale=",$$var2,".  Net change=",$$var3)
	display $trace
	play "silence.wav"
	
	wait 0
	$count += 1
		
	endwhile
       
BYE:
	play "thank.wav"
	hangup
	goto MAIN
	
	

ONHANGUP:
	hangup
	goto MAIN



ONSYSTEMERROR:
	log $error
	display $error
	hangup
	goto MAIN