Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix xml parsing
Browse files Browse the repository at this point in the history
Change-Id: I3b5da88e95af40fcd718d9e57817acf2388753e9
  • Loading branch information
yinchenyang committed Dec 12, 2019
1 parent f70c1cb commit 74417e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
29 changes: 26 additions & 3 deletions model/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package model

import (
"errors"
"fmt"
"github.com/SlyMarbo/rss"
"github.com/indes/flowerss-bot/config"
"io/ioutil"
"log"
"net/http"
"strings"
"unicode"
)

type Source struct {
ID uint `gorm:"primary_key";"AUTO_INCREMENT"`
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
Link string
Title string
ErrorCount uint
Expand Down Expand Up @@ -49,9 +54,27 @@ func FindOrNewSourceByUrl(url string) (*Source, error) {
source.Link = url

// parsing task
feed, err := rss.Fetch(url)
feed, err := rss.FetchByFunc(func(url string) (resp *http.Response, err error) {
resp, err = http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var data []byte
if data, err = ioutil.ReadAll(resp.Body); err != nil {
return nil, err
}
resp.Body = ioutil.NopCloser(strings.NewReader(strings.Map(func(r rune) rune {
if unicode.IsPrint(r) {
return r
}
return -1
}, string(data))))
return
}, url)

if err != nil {
return nil, errors.New("Feed 抓取错误")
return nil, fmt.Errorf("Feed 抓取错误 %v", err)
}

source.Title = feed.Title
Expand Down
2 changes: 1 addition & 1 deletion model/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package model
import "errors"

type Subscribe struct {
ID uint `gorm:"primary_key";"AUTO_INCREMENT"`
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
UserID int64
SourceID uint
EnableNotification int
Expand Down

0 comments on commit 74417e7

Please sign in to comment.