package main import ( "C" "errors" "fmt" "net/http" "time" "github.com/PuerkitoBio/goquery" ) func GetSourceName() string { return "dilbert" } func GetFeedList() []map[string]string { var ret []map[string]string feedMap := make(map[string]string) feedMap["slug"] = "dilbert" feedMap["name"] = "Dilbert" feedMap["author"] = "Scott Adams" feedMap["source"] = GetSourceName() ret = append(ret, feedMap) return ret } func GetFeedUrl(slug string, date time.Time) (string, error) { return fmt.Sprintf( "http://dilbert.com/strip/%4d-%02d-%02d", date.Year(), date.Month(), date.Day(), ), nil } func GetFeedDesc(slug string, date time.Time) (string, error) { url, err := GetFeedUrl(slug, date) if err != nil { return "", err } res, err := http.Get(url) if err != nil { return "", err } defer res.Body.Close() if res.StatusCode != 200 { return "", errors.New(fmt.Sprintf("Status code error: %d %s", res.StatusCode, res.Status)) } // Load the HTML document doc, err := goquery.NewDocumentFromReader(res.Body) if err != nil { return "", err } // Find the Picture src, exists := doc.Find("img.img-comic").Attr("src") if !exists { return "", errors.New("Couldn't find image source") } return "", nil }