2021-06-10 15:49:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-10-20 15:50:39 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
2021-06-10 15:49:42 +00:00
|
|
|
|
2024-10-20 15:50:39 +00:00
|
|
|
"git.ddd.rip/ptrcnull/html"
|
|
|
|
)
|
2021-06-10 15:49:42 +00:00
|
|
|
|
2024-10-20 15:50:39 +00:00
|
|
|
const BOLD = "\033[1m"
|
|
|
|
const RESET = "\033[0m"
|
2021-06-10 15:49:42 +00:00
|
|
|
|
2024-10-20 15:50:39 +00:00
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
fmt.Println("usage: pkgs <filename>")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
file := os.Args[1]
|
|
|
|
|
|
|
|
res, err := http.Get("https://pkgs.alpinelinux.org/contents?file=" + file + "&path=&name=&branch=edge&arch=x86_64")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
node, err := html.ParseDocument(res.Body)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
tbody := node.QuerySelector("tbody")
|
|
|
|
if tbody == nil {
|
|
|
|
fmt.Println("cannot find tbody")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
reply := ""
|
|
|
|
tbody.ForEach(func(row *html.Node) {
|
|
|
|
cells := row.Children()
|
|
|
|
if len(cells) == 0 {
|
|
|
|
return
|
2021-06-10 15:49:42 +00:00
|
|
|
}
|
2024-10-20 15:50:39 +00:00
|
|
|
if len(cells) < 5 {
|
|
|
|
reply = "Not found :("
|
|
|
|
return
|
2021-06-10 15:49:42 +00:00
|
|
|
}
|
2024-10-20 15:50:39 +00:00
|
|
|
reply += BOLD + cells[1].TrimmedText() + RESET + "\n" + cells[0].TrimmedText() + "\n\n"
|
2021-06-10 15:49:42 +00:00
|
|
|
})
|
2024-10-20 15:50:39 +00:00
|
|
|
reply = strings.Trim(reply, "\n")
|
|
|
|
fmt.Println(reply)
|
2021-06-10 15:49:42 +00:00
|
|
|
}
|