Guest User

Retrieve Wikipedia user watchlist with Mathematica

a guest
Aug 11th, 2013
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. (* returns True or False for success or failure *)
  2. Login[username_String, password_String] :=
  3. Module[{url = "http://en.wikipedia.org/w/api.php",
  4. parameters = {"action" -> "login", "lgname" -> username,
  5. "lgpassword" -> password, "format" -> "json"}},
  6. MatchQ["result" /. ("login" /.
  7. ImportString[
  8. If[MatchQ[#, "NeedToken"],
  9. URLFetch[url, "Method" -> "POST",
  10. "Parameters" -> Append[parameters, "lgtoken" -> #2]],
  11. Return@False] & @@ ({"result",
  12. "token"} /. ("login" /.
  13. ImportString[
  14. URLFetch[url, "Method" -> "POST",
  15. "Parameters" -> parameters], "JSON"])), "JSON"]),
  16. "Success"]]
  17.  
  18. (* retrieves watchlist *)
  19. Replace["title",
  20. Flatten[Replace["watchlistraw",
  21. Rest@NestWhileList[
  22. ImportString[
  23. URLFetch[
  24. "http://en.wikipedia.org/w/api.php?action=query&list=\
  25. watchlistraw&format=json&wrlimit=500" <>
  26. If[Length@# > 1, "&wrcontinue=" <> #[[1, 2, 1, 2, 1, 2]],
  27. ""]], "JSON"] &, {}, Length@# != 1 &]], 1]]
Add Comment
Please, Sign In to add comment