Created
March 13, 2014 19:53
-
-
Save ptantiku/9535638 to your computer and use it in GitHub Desktop.
Download stock data from BLS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Downloading stock data, one file per date | |
# required packages: php5-cli wget | |
# downloaded files have format of: name, date(yymmdd), open, high, low, close, volume(stocks), value(baht) | |
$start_year = 2003; | |
for($y=$start_year; $y<=2014; $y++){ | |
for($m=1; $m<=12; $m++ ){ | |
for($d=1; $d<=31; $d++){ | |
$t = strtotime("$y-$m-$d"); | |
if($t===FALSE || $t>strtotime("now") || date('m',$t)!=$m) break; | |
$dow = intval(date('N', $t)); //1-Monday, 7-Sunday | |
if(1<=$dow && $dow<=5){ | |
$url = sprintf('http://realtime.bualuang.co.th/myeasy/realtime/quotation/txt/%02d%02d%4d.txt',$d,$m,$y); | |
system("wget $url"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment