Implement Parsing of Multiple Articles on one Page #5

Merged
yequari merged 5 commits from multiple-articles-2 into master 2024-04-18 18:55:50 +00:00
2 changed files with 10 additions and 2 deletions
Showing only changes of commit 3ea57fe25c - Show all commits

View File

@ -53,6 +53,7 @@ type SitePage struct {
Title string
Root *html.Node
Errors []error
ErrStr string
}
func fetchPage(url string) (string, error) {
@ -84,6 +85,7 @@ func parseTime(timestr string) (time.Time, error) {
"2006-01-02 15:04",
"2006-01-02T15:04:05",
"2006-01-02T15:04",
// "2006-02-01 15:04",
}
var pagetime time.Time
var err error
@ -178,9 +180,9 @@ func (p *SitePage) Parse() ([]*FeedItem, error) {
for _, perr := range p.Errors {
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) {
@ -224,6 +226,7 @@ func NewFeedInfo(name, base_url, desc, author string, page_urls...string) (*Feed
info.Errors[url] = err.Error()
} else {
info.Items = append(info.Items, pageItems...)
info.Errors[url] = page.ErrStr
}
}
return &info, nil

View File

@ -45,6 +45,11 @@ func TestTimeParsing(t *testing.T) {
`<article><time datetime="2004-05-14T07:30">May 14 2004</time>hello world</article>`,
"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 {