User:Tony Sidaway/scripts/categorymembers

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Iron Chicken script:



(let* (
       [category-string
          (with-input-from-string (second (argv)) read-string)]
       [category (string-substitute
         "^(\\[\\[)*(:)([Cc]ategory:\\s)*([^\\[]*)(\\]\\])*$" "\\4"
         category-string)]
       [output-page
          (if (> (length (argv)) 2)
            (wiki-unlink (with-input-from-string (third (argv)) read-string))
            (string-append "User:" client-username "/categorymembers/" category))]
       [ftitle (fgetattrvalue "//@title")]
       [fcategory 
         (make-get-next-page
           (lambda opt
             (and-let* (
               [res
                 (api
                           (append
                             `((action . "query")
                              (list . "categorymembers")
                              (cmlimit . 500)
                              (cmcategory . ,category))
                            (apply append opt)))])
               (cadr res)))
           "//cm")]
       [result
         (let loop ([lst '()] [s (fcategory)])
           (if s
              (loop (append lst (list (ftitle s))) (fcategory))
              lst))])
  (write-wiki-page
    output-page
    (string-append
       (wiki-heading 2 (string-append "Members of Category: " category ""))
       (big-apply string-append
           (wiki-list (map wiki-link result))))
    (string-append
      "Members of Category: " category " "
      "compiled for " client-username " by " bot-username " using " (irnc-user-agent))))