Skip to content

Instantly share code, notes, and snippets.

@keesterbrugge
Last active September 30, 2020 10:33
Show Gist options
  • Save keesterbrugge/1647adf853573ea619848a3dfe72ded7 to your computer and use it in GitHub Desktop.
Save keesterbrugge/1647adf853573ea619848a3dfe72ded7 to your computer and use it in GitHub Desktop.
(require '[cheshire.core :as json]
'[clj-http.client :as client]
'[tech.ml.dataset :as ds]
'[flatland.ordered.set :refer [ordered-set]]
)
;; used a qubole query to get all app-id's
(defonce ds (ds/->dataset "/tmp/full_result_407911382.csv"))
;; ordered by # of impressions.
(def ordered-app-id-numbers
(->> (get (ds/sort-by-column "impressions" > ds) "app_id")
vec
(apply ordered-set )
(remove nil?)
(filter #(clojure.core/re-matches #"^[0-9]+$" %))))
(defn lookup-app-name-by-id2
[app-id-string]
(let [response (client/get (str "https://itunes.apple.com/lookup?id=" app-id-string))
body (json/parse-string (:body response))
app-name (get-in body ["results" 0 "trackName"]) ]
app-name))
;; write to csv. st
;; such that if api blocks I have everything thus far in file.
;; had to restart couple of times cause the
;; api gave me error 503.
(defn strip-name [name]
(clojure.string/replace name #"[^\w-\s\:\–\&\!\.\(\)\|]" ""))
(spit "app-id-name2.csv" "app_id, name, stripped_name \n")
(doseq [app-id-number ordered-app-id-numbers]
(let [app-name (lookup-app-name-by-id2 app-id-number)]
(Thread/sleep 100)
(spit "app-id-name2.csv" (str app-id-number
", "
app-name
", "
(strip-name app-name)
"\n")
:append true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment