Skip to content

Instantly share code, notes, and snippets.

@eko
Last active August 29, 2015 14:24
Show Gist options
  • Save eko/8b3cb709d622e3e86734 to your computer and use it in GitHub Desktop.
Save eko/8b3cb709d622e3e86734 to your computer and use it in GitHub Desktop.
RATP Information trafic
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"fmt"
)
type RatpLine struct {
Name string `json:"name"`
Icon string `json:"icon"`
Level int `json:"level"`
Title string `json:"title"`
Message string `json:"message"`
Url string `json:"url"`
}
type RatpTransport struct {
Name string `json:"name"`
Icon string `json:"icon"`
Url string `json:"url"`
Lines map[string]RatpLine `json:"lines"`
}
type RatpStatus struct {
Rer RatpTransport `json:"rer"`
Metro RatpTransport `json:"metro"`
Tram RatpTransport `json:"tram"`
}
type RatpApi struct {
Now string `json:"now"`
Unavailable string `json:"unavailable"`
Status RatpStatus `json:"status"`
}
func main() {
res, err := http.Get("http://www.ratp.fr/meteo/ajax/data")
if err != nil { panic(err) }
body, err := ioutil.ReadAll(res.Body)
data := RatpApi{}
err = json.Unmarshal(body, &data)
if err != nil { panic(err) }
fmt.Printf("%s", data.Status.Metro.Lines["3"].Message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment