/
generic.go
45 lines (38 loc) · 1.05 KB
/
generic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"github.com/gosexy/to"
"io/ioutil"
"net/http"
"regexp"
//"strings"
)
var (
wowheadUrlRe = regexp.MustCompile(`wowhead.com/\??item=(\d+)`)
wowdbUrlRe = regexp.MustCompile(`wowdb.com/items/(\d+)`)
wowheadUrl = "http://www.wowhead.com/compare?items="
)
// Attempt to find any links in the page that we can
// parse and generate codes for.
func generic(options map[string]interface{}) (TMorphItems, error) {
resp, err := http.Get(to.String(options["url"]))
if err != nil {
return nil, err
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
resp.Body.Close()
matches := wowheadUrlRe.FindAllStringSubmatch(string(data), -1)
var items []string
for _, match := range matches {
items = append(items, match[1])
}
matches = wowdbUrlRe.FindAllStringSubmatch(string(data), -1)
for _, match := range matches {
items = append(items, match[1])
}
//options["url"] = wowheadUrl + strings.Join(items, ";")
//return wowhead(options)
return wowapi(items)
}