Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support RFC1123 time format #24

Merged
merged 3 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ executors:
- image: circleci/golang:1.11.6
environment:
GO111MODULE: 'on'
TZ: Asia/Tokyo

commands:
restore_module:
Expand Down
7 changes: 1 addition & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down
10 changes: 9 additions & 1 deletion rss_crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
23 changes: 22 additions & 1 deletion rss_crawler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
13 changes: 11 additions & 2 deletions rss_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
<description>subtitle</description>
<lastBuildDate>Tue, 01 Jan 2019 00:200:00 +0900</lastBuildDate>
<item>
<title>title</title>
<title>title RFC1123Z</title>
<link>http://example.com</link>
<description>summary_content</description>
<pubDate>Tue, 01 Jan 2019 00:00:00 +0900</pubDate>
<guid isPermalink="false">id</guid>
<author>name</author>
<enclosure url="http://example.com/image.png" type="image/png" length="0" />
</item>
<item>
<title>title RFC1123</title>
<link>http://example.com</link>
<description>summary_content</description>
<pubDate>Tue, 01 Jan 2019 00:00:00 JST</pubDate>
<guid isPermalink="false">id</guid>
<author>name</author>
<enclosure url="http://example.com/image.png" type="image/png" length="0" />
</item>
</channel>
</rss>
</rss>