Advertisement
Guest User

mbtaRoutes.go

a guest
Sep 13th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.15 KB | None | 0 0
  1. // mbtaRoutes.go - fetches all of the Routes from MBTA; can pull by route type.
  2. // usage:
  3. //  mbtaRoutes.go -typeid=<numerical route_type ID>
  4. //
  5. package main
  6.  
  7. import (
  8.     "MBTA"
  9.     "encoding/json"
  10.     "flag"
  11.     "fmt"
  12.     "os"
  13. )
  14.  
  15. var apikey string
  16. var apiurl string
  17. var format string
  18. var typeid int
  19.  
  20. // init - initializes flag variables.
  21. func init() {
  22.     flag.StringVar(&apikey, "apikey", "wX9NwuHnZU2ToO7GmGR9uw", "Set MBTA API Route Key")
  23.     flag.StringVar(&apiurl, "apiurl", "http://realtime.mbta.com/developer/api/v2/", "URL of the MBTA API to be used.")
  24.     flag.StringVar(&format, "format", "json", "Specify if you would like a different return type -- default is JSON")
  25.     flag.IntVar(&typeid, "typeid", 9999, "Numerical route type ID to ask for a listing of all routes fora specific route type from MBTA.")
  26. }
  27.  
  28. // check - an error checking function
  29. func check(e error) {
  30.     if e != nil {
  31.         panic(e)
  32.     }
  33. }
  34.  
  35. func main() {
  36.     flag.Parse()
  37.     c := gombta.Client{APIKey: apikey, URL: apiurl}
  38.  
  39.     // get a list of routes by type
  40.     d, err := c.GetRoutes(format)
  41.  
  42.     check(err)
  43.     j, err := json.MarshalIndent(d, "", " ")
  44.     fmt.Printf("RouteTypes: ")
  45.     os.Stdout.Write(j)
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement