-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cce8472
commit b2d6333
Showing
8 changed files
with
447 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/tidwall/gjson" | ||
) | ||
|
||
type Blogger struct { | ||
} | ||
|
||
func NewBlogger() *Blogger { | ||
return &Blogger{} | ||
} | ||
|
||
func (b *Blogger) Feed(ctx context.Context, id string) ([]FeedItem, error) { | ||
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, | ||
fmt.Sprintf("https://www.googleapis.com/blogger/v2/blogs/%s/posts", id), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
q := url.Values{} | ||
q.Add("key", "AIzaSyBU3_KGZO90Vu_s8Lhbl7lJAEsaIouAEaY") | ||
q.Add("fetchBodies", "true") | ||
q.Add("maxResults", "20") | ||
req.URL.RawQuery = q.Encode() | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
items := []FeedItem{} | ||
for _, blog := range gjson.GetBytes(body, "items").Array() { | ||
time, err := time.Parse(time.RFC3339, blog.Get("published").String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
item := FeedItem{ | ||
ID: blog.Get("id").String(), | ||
TS: time.Unix(), | ||
Source: "blogger", | ||
URL: blog.Get("url").String(), | ||
Content: blog.Get("content").String(), | ||
} | ||
items = append(items, item) | ||
} | ||
return items, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/mmcdole/gofeed" | ||
) | ||
|
||
type DeviantArt struct { | ||
} | ||
|
||
func NewDeviantArt() *DeviantArt { | ||
return &DeviantArt{} | ||
} | ||
|
||
func (d *DeviantArt) Feed(ctx context.Context, id string) ([]FeedItem, error) { | ||
fp := gofeed.NewParser() | ||
feed, err := fp.ParseURL(fmt.Sprintf("https://backend.deviantart.com/rss.xml?q=gallery:%s", id)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
items := []FeedItem{} | ||
for _, art := range feed.Items { | ||
var image string | ||
if media, ok := art.Extensions["media"]; ok { | ||
if content, ok := media["content"]; ok && len(content) > 0 { | ||
if url, ok := content[0].Attrs["url"]; ok { | ||
image = url | ||
} | ||
} | ||
} | ||
|
||
if image == "" { | ||
continue | ||
} | ||
|
||
item := FeedItem{ | ||
ID: art.Title, | ||
TS: art.PublishedParsed.Unix(), | ||
Source: "deviantart", | ||
Media: []FeedItemMedia{{ | ||
URL: image, | ||
Kind: "image", | ||
}}, | ||
URL: art.Link, | ||
Content: art.Title, | ||
} | ||
items = append(items, item) | ||
} | ||
return items, nil | ||
} |
Oops, something went wrong.