Location: PHPKode > projects > MpiBot > modules/GetStock.mod.php
<?php
	/* (C) Copyright 2004 Armond Carroll.  All rights reserved.
	   Distributed under the BSD License.  Please see license.txt for license,
	   or http://www.opensource.org/licenses/bsd-license.php.

	   http://mpibot.sourceforge.net

	   Purpose of this file:
	   	To provide a basic module for retrieving stock quotes.

	   File Version: 1.0
	   Last Modified: ????

	   NOTE: This uses a Web Service Provided by:
	   	http://www.swanandmokashi.com/HomePage/WebServices/
	*/

	class GetStock extends BaseModule {
		public function on_trigger($i) {
			global $bot;
			if($i['trigger']['command'] == 'stock') {
				$stock = simplexml_load_file(urlencode('http://www.swanandmokashi.com/HomePage/WebServices/StockQuotes.asmx/GetStockQuotes?QuoteTicker=' . $i['trigger']['parameter']));
				if($stock->Quote->StockQuote == 0) {
					$bot->say($i['privmsg']['reply-to'], $i['trigger']['parameter'] . ' is unavailable or does not exist');
				} else {
					if($stock->Quote->Change < 0) { $status = 'down (' . $stock->Quote->Change . ')'; } elseif($stock->Quote->Change > 0) { $status = 'up (' . $stock->Quote->Change . ')'; } else { $status = 'unchanged'; }
					$bot->say($i['privmsg']['reply-to'], ucwords(strtolower($stock->Quote->CompanyName)) . ' is as of ' . $stock->Quote->LastUpdated . ' ' . $status . ' at ' . $stock->Quote->StockQuote . '. (Volume ' . $stock->Quote->Volume . '; Open: ' . $stock->Quote->OpenPrice . '; Cap: ' . $stock->Quote->MarketCap . '; Day High: ' . $stock->Quote->DayHighPrice . '; Day Low: ' . $stock->Quote->DayLowPrice . ')');
				}
			}
		}
	}
?>
Return current item: MpiBot