Created
September 10, 2019 06:39
-
-
Save peterhellberg/e7a73807390c3ab6644da50ec8346a3a to your computer and use it in GitHub Desktop.
Generate screenshots.json for https://gui.neocities.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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