Hey All,

ClojurePY is actually quite amazing. It has none of the complexities with
libraries and projects like Clojure and is suitable for crunching data
(because it's on Python) unlike Node.js/Clojurescript. You can use all the
python libraries. You can even import ipdb and step through your code
without any modifications to the ClojurePY source tree. Even the REPL is
better by default.

Just try
sudo easy_install clojure-py

Then, type clojurepy at your shell to run it!

Then, put this crappy script into emailScraper.clj to automagically listen
to IMAP emails from Gmail:
Be sure to download imapidle.py from
https://raw.github.com/athoune/imapidle/master/src/imapidle.py and place it
in the same directory as emailScraper.clj
Then do $ clojurepy emailScraper.clj. No leiningen! No compilation! Just
run it!

(ns emailScraper)
; adding current directory to path
(require 'os)
(require 'sys)
(require 'time)

;(.chdir os "/Users/seanneilan/BucketsOfNantucket")

(.append sys/path (.abspath os/path (.-curdir os/path)))

; using imapidle in clojurepy
;https://raw.github.com/athoune/imapidle/master/src/imapidle.py


(require 'imapidle)
(def m (.IMAP4_SSL (.-imaplib imapidle) "imap.gmail.com"))
(def fetcher (.IMAP4_SSL (.-imaplib imapidle) "imap.gmail.com"))
(require 'getpass)
(require 'pyzmail)
;(require 'ipdb)

(def pass "Your password here!")

(.login m "your gmail here" pass) ; type in your password here
(.login fetcher "your gmail here" pass)
(.select m)


(defn process-message [message]
  ;(println message)
  (.select fetcher)
  (let [raw-msg (.fetch fetcher (int (first message)) "(BODY.PEEK[])")
        msg (.message_from_string pyzmail (-> raw-msg
                                            second
                                            first
                                            second))
        from (.get_address msg "from")
        to (.get_addresses msg "to")
        cc (.get_addresses msg "cc")
        bcc (.get_addresses msg "bcc")
        subject (.get_subject msg)
        attachments (filter
                     #(nil? (.-is_body msg))
                     (.-mailparts msg))
        text_body (filter
                   #(= (.-is_body %) "text/plain")
                   (.-mailparts msg))
        html_body (filter
                   #(= (.-is_body %) "text/html")
                   (.-mailparts msg))
        body (if (empty? html_body) (first text_body) (first html_body))
        body (.get_payload body)]
    (println body)))


(dorun (map process-message (.idle m)))

(comment
(loop [messages (.idle m)]
  (println (first messages))
  (recur (rest messages))))


I'm surprised ClojurePY hasn't received more attention.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to