Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate screenshots.json for https://gui.neocities.org
package main
import (
"encoding/json"
"os"
"strings"
"github.com/gocolly/colly"
)
const URL = "https://random.waxy.org/images/screenshots/"
//go:generate sh -c "go run generate-screenshots.go > screenshots.json"
func main() {
c := colly.NewCollector(colly.MaxDepth(1))
var screenshots []string
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
link := e.Attr("href")
a := e.Request.AbsoluteURL(link)
if strings.HasSuffix(a, "Jurassic%20Park/") {
c.Visit(a)
}
if strings.HasSuffix(a, ".jpg") || strings.HasSuffix(a, ".png") {
screenshots = append(screenshots, a)
}
})
c.Visit(URL)
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(screenshots)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.