func (n *Node) DownloadBoard(board string, lastModified time.Time) ([]*fourchan.Thread, int, string, error) { if data, _, statusCode, lastModified, err := fourchan.EasyGet( fmt.Sprintf("http://api.4chan.org/%s/threads.json", board), lastModified); err == nil { var bp []*fourchan.BoardPage if err := json.Unmarshal(data, &bp); err != nil { return nil, statusCode, lastModified, err } if statusCode != 304 { n.setBoardState(board, string(data)) } var t []*fourchan.Thread for _, page := range bp { for _, thread := range page.Threads { thread.Board = board t = append(t, thread) } } return t, statusCode, lastModified, nil } else { return nil, 500, "", err } }
func DownloadThread(board string, thread int) (*fourchan.Thread, error) { url := fmt.Sprintf("http://api.4chan.org/%s/res/%d.json", board, thread) if data, _, _, _, err := fourchan.EasyGet(url, time.Time{}); err == nil { var t fourchan.Thread if err := json.Unmarshal(data, &t); err == nil { t.Board = board t.No = thread for idx, _ := range t.Posts { t.Posts[idx].Board = board } return &t, nil } else { return &t, err } } else { return &fourchan.Thread{}, err } }