Add --language option to allow specifying language subdomain
This commit is contained in:
parent
32c06824fb
commit
e4205cef14
20
wp2git.d
20
wp2git.d
|
@ -11,10 +11,10 @@ import litexml;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
string name;
|
string name, language="en";
|
||||||
bool usage, noImport;
|
bool usage, noImport;
|
||||||
foreach (arg; args[1..$])
|
for (int i=1; i<args.length; i++)
|
||||||
switch (arg)
|
switch (args[i])
|
||||||
{
|
{
|
||||||
case "-h":
|
case "-h":
|
||||||
case "--help":
|
case "--help":
|
||||||
|
@ -23,10 +23,15 @@ int main(string[] args)
|
||||||
case "--no-import":
|
case "--no-import":
|
||||||
noImport = true;
|
noImport = true;
|
||||||
break;
|
break;
|
||||||
|
case "--language":
|
||||||
|
if (++i==args.length)
|
||||||
|
throw new Exception("Language expected");
|
||||||
|
language = args[i];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (name)
|
if (name)
|
||||||
throw new Exception("Multiple article name arguments");
|
throw new Exception("Multiple article name arguments");
|
||||||
name = arg;
|
name = args[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +42,7 @@ int main(string[] args)
|
||||||
fwritefln(stderr, "Supported options:");
|
fwritefln(stderr, "Supported options:");
|
||||||
fwritefln(stderr, " -h --help Display this help");
|
fwritefln(stderr, " -h --help Display this help");
|
||||||
fwritefln(stderr, " --no-import Don't invoke ``git fast-import'' and only generate the fast-import data");
|
fwritefln(stderr, " --no-import Don't invoke ``git fast-import'' and only generate the fast-import data");
|
||||||
|
fwritefln(stderr, " --language LANG Specify the Wikipedia language subdomain (default: en)");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +52,7 @@ int main(string[] args)
|
||||||
if (name.length>=2 && name[0]=='"' && name[$-1]=='"')
|
if (name.length>=2 && name[0]=='"' && name[$-1]=='"')
|
||||||
name = name[1..$-1]; // strip quotes
|
name = name[1..$-1]; // strip quotes
|
||||||
|
|
||||||
if (spawnvp(P_WAIT, "curl", ["curl", "-d", "\"\"", "http://en.wikipedia.org/w/index.php?title=Special:Export&pages=" ~ encodeComponent(name), "-o", "history.xml"]))
|
if (spawnvp(P_WAIT, "curl", ["curl", "-d", "\"\"", "http://" ~ language ~ ".wikipedia.org/w/index.php?title=Special:Export&pages=" ~ encodeComponent(name), "-o", "history.xml"]))
|
||||||
throw new Exception("curl error");
|
throw new Exception("curl error");
|
||||||
|
|
||||||
fwritefln(stderr, "Loading history...");
|
fwritefln(stderr, "Loading history...");
|
||||||
|
@ -67,10 +73,10 @@ int main(string[] args)
|
||||||
string text = child["text"].text;
|
string text = child["text"].text;
|
||||||
fwritefln(stderr, "Revision %s by %s: %s", id, committer, summary);
|
fwritefln(stderr, "Revision %s by %s: %s", id, committer, summary);
|
||||||
|
|
||||||
summary ~= "\n\nhttp://en.wikipedia.org/w/index.php?oldid=" ~ id;
|
summary ~= "\n\nhttp://" ~ language ~ ".wikipedia.org/w/index.php?oldid=" ~ id;
|
||||||
data ~=
|
data ~=
|
||||||
"commit refs/heads/master\n" ~
|
"commit refs/heads/master\n" ~
|
||||||
"committer " ~ committer ~ " <" ~ committer ~ "@en.wikipedia.org> " ~ ISO8601toRFC2822(child["timestamp"].text) ~ "\n" ~
|
"committer " ~ committer ~ " <" ~ committer ~ "@" ~ language ~ ".wikipedia.org> " ~ ISO8601toRFC2822(child["timestamp"].text) ~ "\n" ~
|
||||||
"data " ~ .toString(summary.length) ~ "\n" ~
|
"data " ~ .toString(summary.length) ~ "\n" ~
|
||||||
summary ~ "\n" ~
|
summary ~ "\n" ~
|
||||||
"M 644 inline " ~ name ~ ".txt\n" ~
|
"M 644 inline " ~ name ~ ".txt\n" ~
|
||||||
|
|
Loading…
Reference in New Issue