catinello.eu/x/cpuid@v0.0.0-20231214173555-81a76c018636/testdata/getall.go (about) 1 //go:build ignore 2 3 package main 4 5 import ( 6 "archive/zip" 7 _ "bytes" 8 "fmt" 9 "io" 10 "net/http" 11 "os" 12 "strings" 13 14 "golang.org/x/net/html" 15 ) 16 17 // Download all CPUID dumps from http://users.atw.hu/instlatx64/ 18 func main() { 19 resp, err := http.Get("http://users.atw.hu/instlatx64/?") 20 if err != nil { 21 panic(err) 22 } 23 24 node, err := html.Parse(resp.Body) 25 if err != nil { 26 panic(err) 27 } 28 29 file, err := os.Create("cpuid_data.zip") 30 if err != nil { 31 panic(err) 32 } 33 defer file.Close() 34 gw := zip.NewWriter(file) 35 36 var f func(*html.Node) 37 f = func(n *html.Node) { 38 if n.Type == html.ElementNode && n.Data == "a" { 39 for _, a := range n.Attr { 40 if a.Key == "href" { 41 err := ParseURL(a.Val, gw) 42 if err != nil { 43 panic(err) 44 } 45 break 46 } 47 } 48 } 49 for c := n.FirstChild; c != nil; c = c.NextSibling { 50 f(c) 51 } 52 } 53 54 f(node) 55 err = gw.Close() 56 if err != nil { 57 panic(err) 58 } 59 } 60 61 func ParseURL(s string, gw *zip.Writer) error { 62 if strings.HasSuffix(s, "CPUID.txt") { 63 fmt.Println("Adding", "http://users.atw.hu/instlatx64/"+s) 64 resp, err := http.Get("http://users.atw.hu/instlatx64/" + s) 65 if err != nil { 66 fmt.Println("Error getting ", s, ":", err) 67 } 68 defer resp.Body.Close() 69 w, err := gw.Create(s) 70 if err != nil { 71 return err 72 } 73 74 _, err = io.Copy(w, resp.Body) 75 if err != nil { 76 return err 77 } 78 } 79 return nil 80 }