Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* returns True or False for success or failure *)
- Login[username_String, password_String] :=
- Module[{url = "http://en.wikipedia.org/w/api.php",
- parameters = {"action" -> "login", "lgname" -> username,
- "lgpassword" -> password, "format" -> "json"}},
- MatchQ["result" /. ("login" /.
- ImportString[
- If[MatchQ[#, "NeedToken"],
- URLFetch[url, "Method" -> "POST",
- "Parameters" -> Append[parameters, "lgtoken" -> #2]],
- Return@False] & @@ ({"result",
- "token"} /. ("login" /.
- ImportString[
- URLFetch[url, "Method" -> "POST",
- "Parameters" -> parameters], "JSON"])), "JSON"]),
- "Success"]]
- (* retrieves watchlist *)
- Replace["title",
- Flatten[Replace["watchlistraw",
- Rest@NestWhileList[
- ImportString[
- URLFetch[
- "http://en.wikipedia.org/w/api.php?action=query&list=\
- watchlistraw&format=json&wrlimit=500" <>
- If[Length@# > 1, "&wrcontinue=" <> #[[1, 2, 1, 2, 1, 2]],
- ""]], "JSON"] &, {}, Length@# != 1 &]], 1]]
Add Comment
Please, Sign In to add comment