Het Satasiya | c34b3ea | 2022-02-06 17:28:49 -0800 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | // To run the demo, ensure that you have a file named scouting_config.json at the workspace root with your TBA api key in it. |
| 4 | import ( |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 5 | "encoding/json" |
| 6 | "flag" |
| 7 | "fmt" |
Het Satasiya | c34b3ea | 2022-02-06 17:28:49 -0800 | [diff] [blame] | 8 | "log" |
| 9 | |
| 10 | "github.com/davecgh/go-spew/spew" |
| 11 | "github.com/frc971/971-Robot-Code/scouting/scraping" |
| 12 | ) |
| 13 | |
Philipp Schrader | c49eaf7 | 2023-02-26 16:56:52 -0800 | [diff] [blame] | 14 | func dumpData[T interface{}](jsonPtr *bool, category string) { |
| 15 | // Get all the data. |
| 16 | data, err := scraping.GetAllData[T](2016, "nytr", "", category) |
| 17 | if err != nil { |
| 18 | log.Fatal("Failed to scrape ", category, " data: ", err) |
| 19 | } |
| 20 | |
| 21 | // Dump the data. |
| 22 | if *jsonPtr { |
| 23 | jsonData, err := json.MarshalIndent(data, "", " ") |
| 24 | if err != nil { |
| 25 | log.Fatal("Failed to turn ranking list into JSON: ", err) |
| 26 | } |
| 27 | fmt.Println(string(jsonData)) |
| 28 | } else { |
| 29 | spew.Dump(data) |
| 30 | } |
| 31 | } |
| 32 | |
Het Satasiya | c34b3ea | 2022-02-06 17:28:49 -0800 | [diff] [blame] | 33 | func main() { |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 34 | jsonPtr := flag.Bool("json", false, "If set, dump as JSON, rather than Go debug output.") |
Yash Chainani | 4e2b646 | 2022-03-26 15:23:17 -0700 | [diff] [blame] | 35 | demoCategory := flag.String("category", "matches", "Decide whether to demo matches or rankings.") |
| 36 | |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 37 | flag.Parse() |
| 38 | |
Yash Chainani | 4e2b646 | 2022-03-26 15:23:17 -0700 | [diff] [blame] | 39 | if *demoCategory == "rankings" { |
Philipp Schrader | c49eaf7 | 2023-02-26 16:56:52 -0800 | [diff] [blame] | 40 | dumpData[scraping.EventRanking](jsonPtr, "rankings") |
Yash Chainani | 4e2b646 | 2022-03-26 15:23:17 -0700 | [diff] [blame] | 41 | } else if *demoCategory == "matches" { |
Philipp Schrader | c49eaf7 | 2023-02-26 16:56:52 -0800 | [diff] [blame] | 42 | dumpData[[]scraping.Match](jsonPtr, "matches") |
Philipp Schrader | d3fac19 | 2022-03-02 20:35:46 -0800 | [diff] [blame] | 43 | } |
Het Satasiya | c34b3ea | 2022-02-06 17:28:49 -0800 | [diff] [blame] | 44 | } |