Nội dung được xóa Nội dung được thêm vào
Tạo trang mới với nội dung “Tôi là con rôbô của thành viên MuDavid. Tiền tố ''mu-'' là tiền tố tiếng Burǔndi chỉ…”
 
Dòng 1:
Tôi là con rôbô của [[Thành viên:MuDavid|thành viên MuDavid]]. Tiền tố ''mu-'' là tiền tố [[:w:Tiếng Kirundi|tiếng Burǔndi]] chỉ con người, còn tiền tố ''ki-'' chỉ đồ vật nói chung.
 
Con bot này được lập trình bằng [[:w:Mathematica|<tt>Mathematica</tt>]]:
 
* defs:
<source>
myagent = "foo";
sitelang = "vi";
sitename = "wiktionary";
username = "bar";
password = "baz";
site = "https://" <> sitelang <> "." <> sitename <> ".org/";
apiname = site <> "w/api.php";
</source>
* đăng nhập, đòi edit token, đăng xuất:
<source>
first[response_] := StringPosition[response, "logintoken"][[1, 2]] + 4
last[response_] :=
FirstCase[StringPosition[response, "\""],
x_ /; x[[1]] > first[response]][[1]] - 2
extractlogintoken[response_] :=
StringTake[response, {first[response], last[response]}]
extractedittoken[response_] :=
Module[{first, last},
first = StringPosition[response, "csrftoken"][[1, 2]] + 4;
last = FirstCase[StringPosition[response, "\""],
x_ /; x[[1]] > first][[1]] - 2;
StringTake[response, {first, last}]]
return = URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "query", "meta" -> "tokens",
"type" -> "login", "format" -> "json"}]
logintoken = extractlogintoken[return];
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "clientlogin",
"loginreturnurl" -> "http://example.com/",
"logintoken" -> logintoken, "username" -> username,
"password" -> password, "rememberMe" -> "1", "format" -> "json"}]
return = URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "query", "meta" -> "tokens",
"format" -> "json"}]
token = extractedittoken[return];
logout :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "logout", "format" -> "json"}]
</source>
* tải mã wiki của một trang:
<source>
loadwiki[word_] :=
URLFetch[site <> "w/index.php?action=raw&title=" <> word,
"UserAgent" -> myagent]
</source>
* sửa trang:
<source>
edit[page_, newtext_, summary_] :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "edit", "title" -> page,
"text" -> newtext, "summary" -> summary, "assert" -> "user",
"token" -> token, "format" -> "json"}]
editnocreate[page_, newtext_, summary_] :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "edit", "title" -> page,
"text" -> newtext, "summary" -> summary, "nocreate" -> "1",
"assert" -> "user", "token" -> token, "format" -> "json"}]
editcreate[page_, newtext_, summary_] :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "edit", "title" -> page,
"text" -> newtext, "summary" -> summary, "createonly" -> "1",
"assert" -> "user", "token" -> token, "format" -> "json"}]
editbot[page_, newtext_, summary_] :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "edit", "title" -> page,
"text" -> newtext, "summary" -> summary, "bot" -> "1",
"assert" -> "bot", "token" -> token, "format" -> "json"}]
editnocreatebot[page_, newtext_, summary_] :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "edit", "title" -> page,
"text" -> newtext, "summary" -> summary, "nocreate" -> "1",
"bot" -> "1", "assert" -> "bot", "token" -> token,
"format" -> "json"}]
editcreatebot[page_, newtext_, summary_] :=
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "edit", "title" -> page,
"text" -> newtext, "summary" -> summary, "createonly" -> "1",
"bot" -> "1", "assert" -> "bot", "token" -> token,
"format" -> "json"}]
hasmessage := (!
StringFreeQ[
URLFetch[apiname, "UserAgent" -> myagent, "Method" -> "POST",
"Parameters" -> {"action" -> "query", "meta" -> "userinfo",
"uiprop" -> "hasmsg", "format" -> "json"}], "messages"])
</source>