Skip to content

Instantly share code, notes, and snippets.

@guipdutra
Created March 8, 2015 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guipdutra/0cbbefe0692e370a4087 to your computer and use it in GitHub Desktop.
Save guipdutra/0cbbefe0692e370a4087 to your computer and use it in GitHub Desktop.
(ns tweet_linkz.core
(:use
[twitter.oauth]
[twitter.callbacks]
[twitter.callbacks.handlers]
[twitter.api.restful])
(:import
(twitter.callbacks.protocols SyncSingleCallback)))
(def my-creds (make-oauth-creds "0yFM1B0UDmtufpLGli5ZKQ"
"CU6pYzpn5xWahR35IQtjr3zHoESWvTBB1ktVRjx1Qk0"
"56802003-bXoHirqGm6tQF8WMmx9m5wFYjWdaIUnL5k0rv328"
"RCvXBAdNBKWb3ZCuDSa3rHWdgfDHRp8qJavL6JeulM"))
(defn extract-link
[tweet]
(re-find #"http://\S+[^\W]" tweet))
(def timeline-tweets
(map :text (statuses-home-timeline :oauth-creds my-creds
:params {:count 200}
:callbacks (SyncSingleCallback. response-return-body
response-throw-error
exception-rethrow))))
(defn links-from-tweets
[tweets]
(remove nil? (map #(extract-link %) tweets)))
(defn -main
[]
(dorun
(map #(println %) (links-from-tweets timeline-tweets))))
@erickpintor
Copy link

Muito legal! :)

Algumas coisinhas que da pra melhorar:

(def extract-link
  (partial re-find #"http://\S+[^\W]"))

; ....

(defn links-from-tweets
  [tweets]
  (remove nil? 
    (map extract-link tweets)))

(defn -main
  []
  (dorun
    (map println 
      (links-from-tweets timeline-tweets))))

Also... da uma olhada nas macros -> e ->>. Elas podem ajudar a colocar comandos em sequência em uma ordem mais lógica.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment