diff --git a/eg/debian/parse-rfc822.hy b/eg/debian/parse-rfc822.hy new file mode 100644 index 0000000..71cbdca --- /dev/null +++ b/eg/debian/parse-rfc822.hy @@ -0,0 +1,40 @@ +#!/usr/bin/env hy +; Copyright (c) Paul R. Tagliamonte , 2013 under the terms +; of the Expat license, a copy of which you have should have recieved with +; the source. + + +(import sys) + + +(defn parse-rfc822-file [path] + "Parse an RFC822 file" + (with-as (open path "r") fd + (parse-rfc822-stream fd))) + + +(defn parse-rfc822-stream [fd] + "Parse an RFC822 stream" + (def bits {}) + (def key null) + (for [line fd] + (if (in ":" line) + (do (def line (.split line ":" 1)) + (def key (.strip (get line 0))) + (def val (.strip (get line 1))) + (assoc bits key val)) + (do + (if (= (.strip line) ".") + (assoc bits key (+ (get bits key) "\n")) + (assoc bits key (+ (get bits key) "\n" (.strip line))))))) + bits) + + +(def block (parse-rfc822-file (get sys.argv 1))) +(def source (get block "Source")) +(print source "is a(n)" (get block "Description")) + + +(import-from sh apt-cache) +(def archive-block (parse-rfc822-stream (.show apt-cache source))) +(print "The archive has version" (get archive-block "Version") "of" source) diff --git a/eg/sunlight/party-count.hy b/eg/sunlight/party-count.hy index 43ffb28..991bb1b 100755 --- a/eg/sunlight/party-count.hy +++ b/eg/sunlight/party-count.hy @@ -1,5 +1,7 @@ #!/usr/bin/env hy -; let's check out the party breakdown for a state +; Copyright (c) Paul R. Tagliamonte , 2013 under the terms +; of the Expat license, a copy of which you have should have recieved with +; the source. (import sys) (import-from sunlight openstates)