 
 USING: accessors ascii assocs colors formatting html.entities
 html.parser html.parser.analyzer html.parser.printer http.client
-io io.styles kernel namespaces sequences splitting urls
+io io.styles kernel namespaces regexp sequences splitting urls
 wrap.strings xml xml.data xml.traversal ;
 FROM: xml.data => tag? ;
 
 IN: wikipedia
 
 SYMBOL: language
-"en" language set-global
+language [ "en" ] initialize
 
 : with-language ( str quot -- )
     language swap with-variable ; inline

: item. ( tag -- )
    children>> [
        dup tag? [
            dup link [ link. drop ] [ children>string write ] if*
        ] [ [ write ] unless-empty ] if
    ] each nl ;

: items. ( seq -- )
    children-tags [ item. ] each nl ;

: historical-url ( timestamp -- url )
    "%B_%d" strftime wikipedia-url ;

: (historical-events) ( timestamp -- seq )
    historical-url http-get nip string>xml "ul" deep-tags-named ;

: items>sequence ( tag -- seq )
    children-tags [ deep-children>string ] map ;

PRIVATE>

: historical-events ( timestamp -- events )
    (historical-events) second items>sequence ;

: historical-events. ( timestamp -- )
    (historical-events) "Events" header. second items. ;

: historical-births ( timestamp -- births )
    (historical-events) third items>sequence ;

: historical-births. ( timestamp -- )
    (historical-events) "Births" header. third items. ;

: historical-deaths ( timestamp -- births )
    (historical-events) fourth items>sequence ;

: historical-deaths. ( timestamp -- )
    (historical-events) "Deaths" header. fourth items. ;

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


: header. ( string -- )
    H{ { font-size 20 } { font-style bold } } format nl ;

: subheader. ( string -- )
    H{ { font-size 16 } { font-style bold } } format nl ;

: link ( tag -- tag/f )
    "a" assure-name over tag-named? [ "a" deep-tag-named ] unless ;
