diff --git a/extra/wolfram-alpha/authors.txt b/extra/wolfram-alpha/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/extra/wolfram-alpha/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/extra/wolfram-alpha/summary.txt b/extra/wolfram-alpha/summary.txt new file mode 100644 index 0000000000..21a95e5b80 --- /dev/null +++ b/extra/wolfram-alpha/summary.txt @@ -0,0 +1 @@ +Query API for Wolfram Alpha diff --git a/extra/wolfram-alpha/wolfram-alpha.factor b/extra/wolfram-alpha/wolfram-alpha.factor new file mode 100644 index 0000000000..5c6368e947 --- /dev/null +++ b/extra/wolfram-alpha/wolfram-alpha.factor @@ -0,0 +1,50 @@ +! Copyright (C) 2011 John Benediktsson +! See http://factorcode.org/license.txt for BSD license + +USING: accessors colors.constants formatting http http.client +images.gif images.http io io.styles kernel namespaces sequences +splitting ui urls.encoding xml xml.data xml.traversal ; + +IN: wolfram-alpha + +SYMBOL: wolfram-api-id + +! "XXXXXX-XXXXXXXXXX" wolfram-api-id set-global + +xml ; + +PRIVATE> + +: wolfram-image. ( query -- ) + query "pod" tags-named [ + [ + "title" attr "%s:\n" sprintf H{ + { foreground COLOR: slate-gray } + { font-name "sans-serif" } + { font-style bold } + } format + ] [ + "img" deep-tags-named [ + "src" attr " " write http-image. + ] each + ] bi + ] each ; + +: wolfram-text. ( query -- ) + query "pod" tags-named [ + [ "title" attr "%s:\n" printf ] + [ + "plaintext" deep-tags-named [ + children>string string-lines + [ " %s\n" printf ] each + ] each + ] bi + ] each ; + +: wolfram. ( query -- ) + ui-running? [ wolfram-image. ] [ wolfram-text. ] if ;