Skip to content

Instantly share code, notes, and snippets.

@seedprod
Created January 9, 2010 00:50
Show Gist options
  • Save seedprod/272623 to your computer and use it in GitHub Desktop.
Save seedprod/272623 to your computer and use it in GitHub Desktop.
Stockr Source
<?php
set_include_path('.' . PATH_SEPARATOR . dirname(__FILE__) .PATH_SEPARATOR . '../library');
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
Zend_Loader::loadClass('Zend_Debug');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Service_Twitter');
$client = new Zend_Http_Client('http://download.finance.yahoo.com/d/quotes.csv?f=nl1d1t1c1ohgvp2k1&e=.csv&s=%5eDJI+%5eIXIC+%5eGSPC');
$response = $client->request();
$body = $response->getBody();
$symbols = explode("\n", $body);
$tweet = '';
foreach($symbols as $v){
if(!empty($v)){
$items = explode(",",$v);
$items = str_replace(array("\"","^"),"",$items);
if($items[1] == 'RTH'){
unset($items[1]);
$items = array_values($items);
}
if(!empty($tweet)) { $tweet .="";}
switch ($items[0]) {
case 'Dow Jones Industr':
$items[0] ='Dow';
break;
case 'NASDAQ Composite':
$items[0] ='Nasdaq';
break;
case 'S&P 500 INDEX':
$items[0] ='S&P';
break;
}
if(empty($pretweet)){
$pretweet = $items[2].' '.$items[3].' - ';
}
if(empty($tweet)){
$tweet = $pretweet;
}
$tweet .= $items[0]." ".$items[1]." ".$items[4]." (".$items[9].") ";
zend_debug::dump(str_replace("\"","",$items));
}
}
zend_debug::dump($tweet);
zend_debug::dump($_GET['u']);
if($_GET['u'] == 't'){
$twitter = new Zend_Service_Twitter('TWITERUSERNAME', 'TWITTERPASSWORD');
$response = $twitter->status->update('$$ '.$tweet);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment