chbrown / twttr

Twitter API client for Clojure supporting REST and Streaming endpoints
35 stars 11 forks source link

filtering search-tweets #2

Closed bitcoinminersuk closed 5 years ago

bitcoinminersuk commented 5 years ago

I am trying to get to grips with twttr and have found it better to work with, however, I am new to clojure and struggling with trying to filter the text from this function

(defn filter-tweets [keyword]
  (api/search-tweets (creds) :params {:q keyword}))

What would be a way of just printing the user_id, screen_name and the text from the tweet?

Really appreciate some help, once I have that done I should be able to peice the rest of it together

chbrown commented 5 years ago

One way:

(println (:id (:user tweet)) (:screen_name (:user tweet)) (:text tweet))

Basic clojure.core provides a legion of other ways, too — destructuring, juxt, get-in, select-keys, etc.

bitcoinminersuk commented 5 years ago

Thanks for the response, I have tried a few variations and when I try the following function I just get the response nil nil nil

(defn filter-tweets [keyword]
  (api/search-tweets (creds) :params {:q keyword})
  (println (:statuses (:user keyword)) (:screen_name (:id_str keyword)) (:text keyword)))

Thanks

chbrown commented 5 years ago

Okay, um, can you read through http://riemann.io/clojure.html#maps (and maybe the rest of that page, if it looks useful) and then come back here if you're still having trouble? You might also find more guides (both written and embodied) at various Clojure forums, e.g.: