Skip to content

Instantly share code, notes, and snippets.

@korobochka
Created February 10, 2013 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save korobochka/4749220 to your computer and use it in GitHub Desktop.
Save korobochka/4749220 to your computer and use it in GitHub Desktop.
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