Пример #1
0
func GetDownloadURL(pluginName string, downloadPageURL string) (downloadURL string, err error) {
	fmt.Printf("[%s] Fetching %s\n", pluginName, downloadPageURL)

	resp, err := http.Get(downloadPageURL)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return "", fmt.Errorf("[%s] HTTP request returned %s", pluginName, resp.Status)
	}

	p := h5.NewParser(resp.Body)
	err = p.Parse()
	if err != nil {
		return "", err
	}

	tree := p.Tree()
	results := DownloadURLSelector.Apply(tree)
	if len(results) < 1 {
		return "", fmt.Errorf("[%s] Download link element was not found (bad selector?)", pluginName)
	}

	el := results[0]
	downloadURL = GetAttr(el, "href")
	return downloadURL, nil
}
Пример #2
0
func Parse(r io.Reader) ([]byte, error) {
	p := h5.NewParser(r)
	err := p.Parse()

	if err != nil {
		return nil, err
	}

	tree := p.Tree()
	resp := Response()

	tree.Walk(func(n *h5.Node) {
		tag := n.Data()
		switch {
		case tag == "p":
			resp.Append(Say(n.Children[0].String()))
		case tag == "audio":
			for _, a := range n.Attr {
				if a.Name == "src" {
					resp.Append(Play(a.Value))
				}
			}
		}
	})

	return xml.MarshalIndent(resp, "", "  ")
}
Пример #3
0
func runHtmlTests(ps []string) int {
	var counter int
	// TODO(jwall): with timings?
	for _, p := range ps {
		if *verbose {
			fmt.Println("Attempting to parse file: ", p)
		}
		f, err := os.Open(p)
		if err != nil {
			fmt.Println("ERROR opening file: ", err)
			counter++
		}
		parse := h5.NewParser(f)
		err = parse.Parse()
		if err != nil {
			if !*verbose {
				fmt.Println("Attempting to parse file: ", p)
			}
			fmt.Println("ERROR parsing file: ", err)
			counter++
		} else {
			if *verbose {
				fmt.Println("SUCCESS!!!")
			}
		}
	}
	return counter
}
Пример #4
0
// b *Build is pasesd by pointer, so the Build struct is modified
// not sure if this is idomatic or just a mess. leaning toward messy
func (b *Build) wasLastBuildGood() int {
	resp, err := http.Get(b.url)
	if err != nil {
		fmt.Printf("error: %s", err)
	}
	fmt.Printf("fetched: %s\n", b.url)
	defer resp.Body.Close()

	p := h5.NewParser(resp.Body)

	p.Parse()

	b.status = parseWasLastBuildGood(p)
	return b.status
}
Пример #5
0
func getRemoteText(url string) (string, error) {
	resp, err := http.Get(url)
	if err != nil {
		return "", err
	}

	p := h5.NewParser(resp.Body)

	err = p.Parse()
	if err != nil {
		return "", NewRemoteError("Parse Error")
	}

	found := collectText(p.Tree())
	return strings.Replace(strings.Join(found, ""), "\n", " ", -1), nil
}