Data analytics of the public parkings in Sofia
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.5 KiB

package main
/*
Parking IDs:
1 : Храм-паметник Ал. Невски
2 : л. Княз Александър I
3 : бул. П. Евтимий
4 : пл. Народно събрание
5 : ул. Гурко - Телефонна палата
6 : бул. Ал. Стамболийски
*/
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"encoding/json"
)
type ParkingStatus struct {
Parkings []struct {
ParkingID string `json:"code"`
Time string `json:"datetimeChecked"`
FreePlaces string `json:"freePlaces"`
} `json:"parkingRes"`
}
func fetch_data() []byte {
url := "https://213.240.235.145/web-site-service/rest/parkingBoardsRequest/allFreePlaces"
//because the certificate of the server is self signed
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()
traffic_rawdata, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return traffic_rawdata
}
func parse_data(data []byte ) ParkingStatus {
var parsed_data ParkingStatus
err := json.Unmarshal(data, &parsed_data)
if err != nil {
fmt.Println(err)
}
// for l := range parsed_data.Parkings {
// fmt.Printf("Parking ID= %v, Time= %v, FreePlaces = %v",
// parsed_data.Parkings[l].ParkingID,
// parsed_data.Parkings[l].Time,
// parsed_data.Parkings[l].FreePlaces )
// fmt.Println()
// }
return parsed_data
}
func main() {
fmt.Printf("%s\n", fetch_data())
fmt.Println()
parse_data(fetch_data() )
}