Created
June 12, 2015 16:24
-
-
Save juhovh/4cd26928225109f4f1f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns pyppejson.core | |
(:require [cheshire.core :refer :all]) | |
(:gen-class)) | |
(def user-paths | |
[[:user] | |
[:retweeted_status :user] | |
[:retweeted_status :quoted_status :user] | |
[:quoted_status :user]]) | |
(defn filter-users [tweet path fields] | |
(update-in tweet path select-keys fields)) | |
(defn filter-tweet [tweet paths] | |
(reduce #(filter-users %1 %2 #{:id_str :name}) tweet paths)) | |
(defn get-all-users [tweet paths] | |
(let [all-users (map #(get-in tweet %) paths)] | |
(zipmap (map :id_str all-users) all-users))) | |
(defn -main | |
[& args] | |
(let [tweet (parse-string (slurp "example-tweet.json") true) | |
tweet-lite (filter-tweet tweet user-paths)] | |
(println "EXTRACTED USERS") | |
(println (get-all-users tweet-lite user-paths)) | |
(println "WHOLE TWEET WITH LITE USERS") | |
(println (generate-string tweet-lite)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXTRACTED USERS | |
{5 {:id_str 5, :name Quoter}, 1 {:id_str 1, :name Pyppe}, 2 {:id_str 2, :name Retweeter}, 0 {:id_str 0, :name Petra Sievinen}} | |
WHOLE TWEET WITH LITE USERS | |
{"filter_level":"low","timestamp_ms":"1433966461293","quoted_status":{"id_str":"4","user":{"id_str":"5","name":"Quoter"},"geo":null,"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"fi"},"entities":{"hashtags":[{"text":"lovedungeon","indices":[57,70]}],"trends":[],"urls":[{"url":"https://t.co/abc","expanded_url":"https://twitter.com/diipadaapa/status/1234","display_url":"twitter.com/diipadaapa/sta…","indices":[72,95]}],"user_mentions":[{"screen_name":"foo","name":"Foo bar","id":102025211,"id_str":"102025211","indices":[0,13]}],"symbols":[]},"retweeted_status":{"hip":"hei","user":{"id_str":"2","name":"Retweeter"},"quoted_status":{"some":"property","user":{"id_str":"1","name":"Pyppe"}}},"lang":"fi","truncated":false,"retweeted":false,"id_str":"608725574924808192","favorited":false,"user":{"id_str":"0","name":"Petra Sievinen"},"retweet_count":0,"favorite_count":0,"created_at":"Wed Jun 10 20:01:01 +0000 2015","text":"Testing"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment