Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created September 10, 2019 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/e7a73807390c3ab6644da50ec8346a3a to your computer and use it in GitHub Desktop.
Save peterhellberg/e7a73807390c3ab6644da50ec8346a3a to your computer and use it in GitHub Desktop.
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