Created
February 10, 2013 10:56
-
-
Save korobochka/4749220 to your computer and use it in GitHub Desktop.
This file contains 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
import std.stdio; | |
import std.parallelism; | |
import std.process; | |
import std.file; | |
int main() | |
{ | |
auto f = File("ids.txt"); | |
auto tp = new TaskPool(32); | |
string[] s; | |
foreach(line; f.byLine()) | |
{ | |
if(line.length == 0) continue; | |
s ~= line.idup; | |
} | |
writeln(s.length); | |
foreach(e; tp.parallel(s, 1)) | |
{ | |
string name = "./data2/" ~ e ~ ".csv"; | |
string link = "http://ichart.finance.yahoo.com/table.csv?s=" ~ e ~ "&a=00&b=1&c=2009&d=11&e=31&f=2012&g=d&ignore=.csv"; | |
string command = "wget -q -O " ~ escapeShellFileName(name) ~ " " ~ escapeShellFileName(link); | |
auto file = DirEntry(name); | |
if(file.exists && file.size > 0) | |
{ | |
writeln("Have ", name); | |
continue; | |
} | |
int res = system(command); | |
if(res != 0) | |
{ | |
writeln("!!! ", res); | |
writeln("Error ", name, " ", command); | |
} | |
if(file.exists && file.size > 0) writeln(file.size); | |
} | |
tp.finish(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment