Implement Parsing of Multiple Articles on one Page #5
|
@ -53,6 +53,7 @@ type SitePage struct {
|
||||||
Title string
|
Title string
|
||||||
Root *html.Node
|
Root *html.Node
|
||||||
Errors []error
|
Errors []error
|
||||||
|
ErrStr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchPage(url string) (string, error) {
|
func fetchPage(url string) (string, error) {
|
||||||
|
@ -84,6 +85,7 @@ func parseTime(timestr string) (time.Time, error) {
|
||||||
"2006-01-02 15:04",
|
"2006-01-02 15:04",
|
||||||
"2006-01-02T15:04:05",
|
"2006-01-02T15:04:05",
|
||||||
"2006-01-02T15:04",
|
"2006-01-02T15:04",
|
||||||
|
// "2006-02-01 15:04",
|
||||||
}
|
}
|
||||||
var pagetime time.Time
|
var pagetime time.Time
|
||||||
var err error
|
var err error
|
||||||
|
@ -178,9 +180,9 @@ func (p *SitePage) Parse() ([]*FeedItem, error) {
|
||||||
for _, perr := range p.Errors {
|
for _, perr := range p.Errors {
|
||||||
errorStrs = append(errorStrs, perr.Error())
|
errorStrs = append(errorStrs, perr.Error())
|
||||||
}
|
}
|
||||||
err = errors.New(strings.Join(errorStrs, "\n"))
|
p.ErrStr = errors.New(strings.Join(errorStrs, "\n")).Error()
|
||||||
}
|
}
|
||||||
return items, err
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSitePage(url string) (*SitePage, error) {
|
func NewSitePage(url string) (*SitePage, error) {
|
||||||
|
@ -224,6 +226,7 @@ func NewFeedInfo(name, base_url, desc, author string, page_urls...string) (*Feed
|
||||||
info.Errors[url] = err.Error()
|
info.Errors[url] = err.Error()
|
||||||
} else {
|
} else {
|
||||||
info.Items = append(info.Items, pageItems...)
|
info.Items = append(info.Items, pageItems...)
|
||||||
|
info.Errors[url] = page.ErrStr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &info, nil
|
return &info, nil
|
||||||
|
|
|
@ -45,6 +45,11 @@ func TestTimeParsing(t *testing.T) {
|
||||||
`<article><time datetime="2004-05-14T07:30">May 14 2004</time>hello world</article>`,
|
`<article><time datetime="2004-05-14T07:30">May 14 2004</time>hello world</article>`,
|
||||||
"2006-01-02T15:04",
|
"2006-01-02T15:04",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"YYYY-DD-MM HH:MM",
|
||||||
|
`<article><time datetime="2004-14-05 07:30">May 14 2004</time>hello world</article>`,
|
||||||
|
"2006-02-01 15:04",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue