     [ [ ascii:blank? ] trim ] map harvest [
         html-unescape 72 wrap-string print nl
     ] each ;
+
+<PRIVATE
+
+: eval-timestamp ( seq -- timestamp )
+    [ today ] [
+        " " join t auto-use? [ eval( -- timestamp ) ] with-variable
+    ] if-empty ;
+
+PRIVATE>
+
+: wikipedia-main ( -- )
+    command-line get [
+        unclip {
+            { "events" [ eval-timestamp historical-events. ] }
+            { "births" [ eval-timestamp historical-births. ] }
+            { "deaths" [ eval-timestamp historical-deaths. ] }
+            { "article" [ [ article. ] each ] }
+            [ "ERROR: Unknown command: " write print drop ]
+        } case
+    ] unless-empty ;
+
+MAIN: wikipedia-main

    historical-get-events sections>sequence ;

: historical-events. ( timestamp -- )
    historical-get-events "Events" header. sections. ;

: historical-births ( timestamp -- births )
    historical-get-births sections>sequence ;

: historical-births. ( timestamp -- )
    historical-get-births "Births" header. sections. ;

: historical-deaths ( timestamp -- births )
    historical-get-deaths sections>sequence ;

: historical-deaths. ( timestamp -- )
    historical-get-deaths "Deaths" header. sections. ;

: article. ( name -- )
    wikipedia-url http-get nip parse-html

! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license

USING: accessors ascii assocs calendar colors combinators
command-line eval formatting html.entities html.parser
html.parser.analyzer html.parser.printer http.client io
io.styles kernel namespaces parser regexp sequences splitting
urls wrap.strings xml xml.data xml.traversal ;
FROM: xml.data => tag? ;

IN: wikipedia
