From 1012c14c046654c7c8214988e6859b7ff16c1d5a Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Tue, 30 Mar 2021 21:26:43 +0900 Subject: [PATCH 1/3] support RFC1123 time format --- rss_crawler.go | 10 +++++++++- rss_crawler_test.go | 23 ++++++++++++++++++++++- rss_test.xml | 13 +++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/rss_crawler.go b/rss_crawler.go index a17c87c..1e88dd9 100644 --- a/rss_crawler.go +++ b/rss_crawler.go @@ -47,7 +47,15 @@ func (crawler *rssCrawler) Crawl() ([]*Item, error) { } func convertRssItemToItem(i *feeds.RssItem) (*Item, error) { - t, err := time.Parse("Mon, 2 Jan 2006 15:04:05 -0700", i.PubDate) + layouts := []string{time.RFC1123, time.RFC1123Z} + var t time.Time + var err error + for _, layout := range layouts { + t, err = time.Parse(layout, i.PubDate) + if err == nil { + break + } + } if err != nil { return nil, errors.Wrap(err, "Parse Error") } diff --git a/rss_crawler_test.go b/rss_crawler_test.go index 503c4ac..760ff29 100644 --- a/rss_crawler_test.go +++ b/rss_crawler_test.go @@ -29,7 +29,28 @@ func TestRSSFetch(t *testing.T) { publishedString := "2019-01-01T00:00:00+09:00" published, _ := time.Parse(time.RFC3339, publishedString) expected := []*feeder.Item{{ - Title: "title", + Title: "title RFC1123Z", + Link: &feeder.Link{ + Href: "http://example.com", + Rel: "", + }, + Source: nil, + Author: &feeder.Author{ + Name: "name", + }, + Description: "summary_content", + ID: "id", + Updated: nil, + Created: &published, + Enclosure: &feeder.Enclosure{ + URL: "http://example.com/image.png", + Type: "image/png", + Length: "0", + }, + Content: "", + }, + { + Title: "title RFC1123", Link: &feeder.Link{ Href: "http://example.com", Rel: "", diff --git a/rss_test.xml b/rss_test.xml index 101c621..de050c8 100644 --- a/rss_test.xml +++ b/rss_test.xml @@ -6,7 +6,7 @@ subtitle Tue, 01 Jan 2019 00:200:00 +0900 - title + title RFC1123Z http://example.com summary_content Tue, 01 Jan 2019 00:00:00 +0900 @@ -14,5 +14,14 @@ name + + title RFC1123 + http://example.com + summary_content + Tue, 01 Jan 2019 00:00:00 JST + id + name + + - \ No newline at end of file + From 33332aaf3422aba8b52c87b1a1025356fee6ecb8 Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Tue, 30 Mar 2021 22:30:29 +0900 Subject: [PATCH 2/3] set timezone --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5ec3380..91d72e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,6 +6,7 @@ executors: - image: circleci/golang:1.11.6 environment: GO111MODULE: 'on' + TZ: Asia/Tokyo commands: restore_module: From 747451aea6ee9ea3bd217353ab58eb49030bec2a Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Tue, 30 Mar 2021 22:30:34 +0900 Subject: [PATCH 3/3] execute go mod tidy --- go.sum | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/go.sum b/go.sum index 082316c..792cd77 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -13,10 +11,7 @@ github.com/otiai10/marmoset v0.4.0 h1:Hg59lQI7qQowBEdsAJ/+VDTEospTBzXX/A1Gsw4mlv github.com/otiai10/marmoset v0.4.0/go.mod h1:t2q6dXWZ9YcFdRREDApX4bCmfQnL3isJ2dgl8ychlXg= github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= -github.com/otiai10/opengraph v1.1.1 h1:zaHbzhegXGqxVpiI7xlQQ0vKBWvHJbagnUjDC40sFtQ= -github.com/otiai10/opengraph v1.1.1/go.mod h1:ZMbPcfiSRSsg3+yrWZCXrgYL6kEK4KpH4GG1iyIvEXs= -github.com/otiai10/opengraph v1.1.2 h1:ajv2DTAh62p6wv1bXxnje+9K/AATJROtjnmk6Ml7Ro8= -github.com/otiai10/opengraph v1.1.2/go.mod h1:ZMbPcfiSRSsg3+yrWZCXrgYL6kEK4KpH4GG1iyIvEXs= +github.com/otiai10/opengraph v1.1.3 h1:4RoX4yckU/eaj34XxwoyNFvuPVrmjcUHMyAgjJL1Pwg= github.com/otiai10/opengraph v1.1.3/go.mod h1:ZMbPcfiSRSsg3+yrWZCXrgYL6kEK4KpH4GG1iyIvEXs= github.com/p1ass/feeds v1.1.1 h1:ah6XlzYVT3RCie+KYeqOgoGvn1IepKYLjI8jzPNeMs8= github.com/p1ass/feeds v1.1.1/go.mod h1:FV21uIHg0+tWMbO9u0qzQmf1cwF5E+nO/ZkfAu1rCAY=