Skip to content

Instantly share code, notes, and snippets.

@robertjlooby
Created October 15, 2013 04:02
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 robertjlooby/6986296 to your computer and use it in GitHub Desktop.
Save robertjlooby/6986296 to your computer and use it in GitHub Desktop.
Using the metra Rail-Time Tracker API
(ns metra
(:require [cheshire.core :refer [generate-string parse-string]
[clj-http.client :as http]))
(defn get-trains []
(let [timestamp (str "/Date(" (.getTime (java.util.Date.)) "-0000)/")
body {:stationRequest {:Corridor "MD-N", :Destination "LIBERTYVIL", :Origin "CUS", :timestamp timestamp}}
response (http/post "http://12.205.200.243/AJAXTrainTracker.svc/GetAcquityTrainData" {:body (generate-string body) :content-type :json})
resp-body (parse-string ((parse-string (response :body) true) :d) true)]
resp-body))
@robertjlooby
Copy link
Author

(def lines {:mdnl {:name "Milwaukee District / North Line"
                         :code "MD-N"}})
(def stations {:union {:name "Chicago Union Station"
                               :code "CUS"}
                    :libertyville {:name "Libertyville"
                                     :code "LIBERTYVIL"}})

;to get a title
(str (get-in stations [:union :name]) " to " (get-in stations [:libertyville :name]))

;to get request body
{:stationRequest {:Corridor (get-in lines [:mdnl code]), :Destination (get-in stations [:libertyville :code]), :Origin (get-in stations [:libertyville :code]), :timestamp timestamp}}

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