all repos — honk @ 7ea17f888b19ca286e5babdbd2ae0913c3781cc1

my fork of honk

bloat.go (view raw)

 1//
 2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
 3//
 4// Permission to use, copy, modify, and distribute this software for any
 5// purpose with or without fee is hereby granted, provided that the above
 6// copyright notice and this permission notice appear in all copies.
 7//
 8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16package main
17
18import (
19	"net/http"
20	"strings"
21
22	"humungus.tedunangst.com/r/webs/junk"
23)
24
25func servewonkles(w http.ResponseWriter, r *http.Request) {
26	url := r.FormValue("w")
27	dlog.Printf("getting wordlist: %s", url)
28	wonkles := getxonker(url, "wonkles")
29	if wonkles == "" {
30		wonkles = savewonkles(url)
31		if wonkles == "" {
32			http.NotFound(w, r)
33			return
34		}
35	}
36	var words []string
37	for _, l := range strings.Split(wonkles, "\n") {
38		words = append(words, l)
39	}
40	j := junk.New()
41	j["wordlist"] = words
42	j.Write(w)
43}
44
45func savewonkles(url string) string {
46	w := getxonker(url, "wonkles")
47	if w != "" {
48		return w
49	}
50	ilog.Printf("fetching wonkles: %s", url)
51	res, err := fetchsome(url)
52	if err != nil {
53		ilog.Printf("error fetching wonkles: %s", err)
54		return ""
55	}
56	w = getxonker(url, "wonkles")
57	if w != "" {
58		return w
59	}
60	w = string(res)
61	savexonker(url, w, "wonkles", "")
62	return w
63}