Created
December 12, 2010 21:35
-
-
Save ossareh/738352 to your computer and use it in GitHub Desktop.
without the issues
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 company-count | |
(:require [work.core :as work]) | |
(:use [clojure.contrib.json]) | |
(:use [clojure.contrib.io :only (read-lines)])) | |
(defonce companies (read-json (slurp "http://api.crunchbase.com/v/1/companies.js"))) | |
(def emp-ranges (agent {})) | |
(defn which-range [n] | |
(cond (nil? n) :unknown | |
(< n 15) :under15 | |
(< n 50) :15to49 | |
(< n 100) :50to99 | |
(< n 501) :100to500 | |
:else :over500)) | |
(defn api-url [company] | |
(str "http://api.crunchbase.com/v/1/company/" (:permalink company) ".js")) | |
(defn update-emp-range! [name emp-cnt] | |
(send emp-ranges | |
(fn [m k] (let [v (get m k {}) | |
v (assoc v name emp-cnt)] | |
(println (str "handled " name)) | |
(assoc m k v))) | |
(which-range emp-cnt))) | |
(defn process-company [co] | |
(let [res (slurp (api-url co)) | |
data (read-json res) | |
emps (:number_of_employees data) | |
name (String. ^String (:name co))] | |
(update-emp-range! name emps)) | |
nil) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment