Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // mbtaRoutes.go - fetches all of the Routes from MBTA; can pull by route type.
- // usage:
- // mbtaRoutes.go -typeid=<numerical route_type ID>
- //
- package main
- import (
- "MBTA"
- "encoding/json"
- "flag"
- "fmt"
- "os"
- )
- var apikey string
- var apiurl string
- var format string
- var typeid int
- // init - initializes flag variables.
- func init() {
- flag.StringVar(&apikey, "apikey", "wX9NwuHnZU2ToO7GmGR9uw", "Set MBTA API Route Key")
- flag.StringVar(&apiurl, "apiurl", "http://realtime.mbta.com/developer/api/v2/", "URL of the MBTA API to be used.")
- flag.StringVar(&format, "format", "json", "Specify if you would like a different return type -- default is JSON")
- flag.IntVar(&typeid, "typeid", 9999, "Numerical route type ID to ask for a listing of all routes fora specific route type from MBTA.")
- }
- // check - an error checking function
- func check(e error) {
- if e != nil {
- panic(e)
- }
- }
- func main() {
- flag.Parse()
- c := gombta.Client{APIKey: apikey, URL: apiurl}
- // get a list of routes by type
- d, err := c.GetRoutes(format)
- check(err)
- j, err := json.MarshalIndent(d, "", " ")
- fmt.Printf("RouteTypes: ")
- os.Stdout.Write(j)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement