-
Notifications
You must be signed in to change notification settings - Fork 4
/
TwemoteStocks.php
58 lines (51 loc) · 1.22 KB
/
TwemoteStocks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @package Twemote
* @copyright Hackersquad (Refer README for details)
* @author Akash Chauhan <akash6190 [at] gmail [dot] com>
* @description Gets the latest stock market info about a set of companies.
*/
//require_once('config.inc.php');
require_once(__DIR__.'/common.php');
class TwemoteStocks
{
private $params;
private $message;
function __construct()
{
$this->message="";
}
public function input($params){
$this->params = $params[0];
}
public function output()
{
return $this->show_stock_quotes($this->params);
}
function show_stock_quotes ($stock_list)
{
$message = "";
$url = "http://quote.yahoo.com/d/quotes.csv?s=". $stock_list . "&f=nl1c1&e=.csv";
$filesize = 2000;
$handle = fopen($url, "r");
$raw_quote_data = fread($handle, $filesize);
fclose($handle);
$quote_array = explode("\n", $raw_quote_data);
//var_dump($quote_array);
foreach ($quote_array as $quote_value)
{
$quote = explode(",", $quote_value);
if(!isset($quote[1]))
{
return $message;
}
$symbol = str_replace("\"", "", $quote[0]);
$value = $quote[1];
$change = $quote[2];
//echo $symbol;
$message = $message.$symbol.": ".$value." , ".$change."\n";
}
return $message;
}
}
?>