]> gitweb.factorcode.org Git - factor.git/commitdiff
wikipedia: quick-and-dirty article printing.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Oct 2013 18:52:53 +0000 (11:52 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Oct 2013 18:52:53 +0000 (11:52 -0700)
extra/wikipedia/wikipedia.factor

index 59fcc513366a4c0c6310d29d3022ac2f4db5f248..5c2e24ebb29f539d1733dba7e24d3443da1b6d80 100644 (file)
@@ -1,9 +1,12 @@
 ! Copyright (C) 2012 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: accessors assocs calendar colors.constants formatting
-http.client io io.styles kernel make sequences urls xml
-xml.data xml.traversal ;
+USING: accessors ascii assocs calendar colors.constants
+formatting html.parser html.parser.analyzer html.parser.printer
+http.client io io.streams.string io.styles kernel make regexp
+sequences splitting urls wrap.strings xml xml.data
+xml.traversal ;
+FROM: xml.data => tag? ;
 
 IN: wikipedia
 
@@ -61,3 +64,14 @@ PRIVATE>
 
 : historical-deaths. ( timestamp -- )
     (historical-events) "Deaths" header. fourth items. ;
+
+: article. ( name -- )
+    "http://en.wikipedia.org/wiki/%s" sprintf
+    http-get nip parse-html "content" find-by-id-between
+    [ html-text. ] with-string-writer string-lines
+    [ [ blank? ] trim ] map harvest [
+        R/ &lt;/ "<" re-replace
+        R/ &gt;/ ">" re-replace
+        R/ &amp;/ "&" re-replace
+        72 wrap-string print nl
+    ] each ;