paddockpass/crawlers/races.go
2020-07-25 00:39:53 +02:00

80 lines
972 B
Go

package crawlers
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/sirupsen/logrus"
)
// GetResultsFromErgast retrieves the results of the races from Ergast API.
func GetResultsFromErgast(year string) {
resp, err := http.Get("http://ergast.com/api/f1/results" + year + ".json")
if err != nil {
panic(err.Error())
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err.Error())
}
defer resp.Body.Close()
var jsonData MRData
err = json.Unmarshal(body, &jsonData)
if err != nil {
logrus.Error(err)
}
fmt.Println(jsonData)
}
/**
MRDATA {
RaceTable {
Races [
{
season
round
url
raceName
date
time
Circuit {
},
Results " [
number,
position,
points,
Driver {}
Constructor {}
grid
laps
status
Time {
millis
time
}
FastestLap {
rank
lap
Time {
time
}
AverageSpeed {
units
speed
}
}
]"
}
]
}
}
**/