本文整理汇总了Golang中github.com/SlyMarbo/rss.Fetch函数的典型用法代码示例。如果您正苦于以下问题:Golang Fetch函数的具体用法?Golang Fetch怎么用?Golang Fetch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fetch函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: doWork
func doWork() (err error) {
feed, err := rss.Fetch(BBC_FEED_URL)
if err != nil {
return err
}
for _, item := range feed.Items[:10] {
if _, ok := visited[item.ID]; ok {
continue
}
n := shruti.Notification{
Title: item.Title,
Url: item.Link,
Key: PROVIDER_NAME + item.ID,
Priority: shruti.PRIO_MED,
Action: shruti.ACT_PUSH,
ProviderName: PROVIDER_NAME,
}
err = sClient.PushNotification(n)
msg := "submitted"
if err != nil {
msg = err.Error()
}
visited[item.ID] = true
log.Println(msg)
}
return nil
}
开发者ID:Omie,项目名称:shruti-providers,代码行数:30,代码来源:bbc.go
示例2: FetchRss
// RSS抓取
func FetchRss(url string, category string) {
feed, err := rss.Fetch(url)
if err != nil {
return
}
err = feed.Update()
if err != nil {
return
}
for k, _ := range feed.Items {
words := strings.TrimSpace(feed.Items[k].Title)
good, details, wordSlice := Scoring(words)
result := &models.YuqingResult{}
// 插入到结果表
result.Id = words
result.Category = category
result.Good = good
result.Detail = details
result.WordSlice = wordSlice
result.Insert()
}
}
开发者ID:treejames,项目名称:woku_old,代码行数:28,代码来源:yuqing.go
示例3: main
func main() {
urls := []string{
"http://rss.slashdot.org/Slashdot/slashdotMain",
"http://www.osnews.com/files/recent.xml",
}
feeds := make([]*rss.Feed, 0)
for _, url := range urls {
feed, err := rss.Fetch(url)
if err != nil {
fmt.Printf("%v: %v\n", url, err)
}
feeds = append(feeds, feed)
err = feed.Update()
if err != nil {
fmt.Printf("%v: %v\n", feed.Link, err)
}
}
fmt.Println("LATEST NEWS\n")
t := template.Must(template.New("webpage").Parse(TEMPLATE))
for _, feed := range feeds {
err := t.Execute(os.Stdout, feed)
if err != nil {
fmt.Printf("error executing template: %v\n", err)
}
}
}
开发者ID:S010,项目名称:test,代码行数:31,代码来源:main2.go
示例4: asyncFetchFeeds
func asyncFetchFeeds(feeds []*rss.Feed) []*HttpResponse {
ch := make(chan *HttpResponse)
responses := []*HttpResponse{}
for _, feed := range feeds {
go func(f *rss.Feed) {
fmt.Printf("Fetching %s\n", f.UpdateURL)
feed, err := rss.Fetch(f.UpdateURL)
if err != nil {
fmt.Printf("Error in response %s. Using old feed.\n", err)
ch <- &HttpResponse{f, err}
} else {
ch <- &HttpResponse{feed, err}
}
}(feed)
}
for {
select {
case r := <-ch:
fmt.Printf("%s was fetched\n", r.feed.UpdateURL)
responses = append(responses, r)
if len(responses) == len(feeds) {
return responses
}
case <-time.After(5 * time.Second):
return responses
}
}
}
开发者ID:henriwi,项目名称:gorss,代码行数:32,代码来源:api.go
示例5: newfeedsplitter
// newfeedsplitter constructs a new feedsplitter
func newfeedsplitter(conn irc.SafeConn, url, name, color string, freq time.Duration, channels []string) (*feedspitter, error) {
f, err := rss.Fetch(url)
if err != nil {
return nil, err
}
fs := &feedspitter{
conn: conn,
feed: f,
name: name,
color: color,
freq: freq,
seen: make(map[string]bool),
channels: channels,
stop: make(chan bool),
}
// initial sweep of seen items
for _, i := range fs.feed.Items {
fs.seen[i.ID] = true
}
return fs, nil
}
开发者ID:treeherder,项目名称:glenda,代码行数:26,代码来源:feedreader.go
示例6: getNewRedditPosts
func getNewRedditPosts(feedUrl, source string) ([]*models.Post, error) {
conn := models.CloneConnection()
defer conn.Close()
// get the feed
feed, err := rss.Fetch(feedUrl)
if err != nil {
return []*models.Post{}, err
}
// iterate the feed and save the new items
posts := make([]*models.Post, 0)
for _, item := range feed.Items {
exists, err := models.PostExists(conn, item.ID)
if err != nil {
return []*models.Post{}, err
}
if !exists {
post := &models.Post{
Title: item.Title,
Source: source,
Url: item.Link,
UniqueId: item.ID,
PublishedAt: item.Date,
}
posts = append(posts, post)
}
}
return posts, nil
}
开发者ID:robmerrell,项目名称:btbboard,代码行数:33,代码来源:reddit_updater.go
示例7: getFeed
func getFeed(w http.ResponseWriter, r *http.Request) {
feedName := chi.URLParam(r, "feedName")
feedSettings, err := config.LoadWidget(feedName)
if err != nil {
render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
return
}
var items config.FeedItems
feed, err := rss.Fetch(feedSettings.RssURL)
if err != nil {
render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
return
}
for _, i := range feed.Items {
items.ParseItem(i)
}
items, err = config.SaveFeed(feedName, items, feedSettings.Count)
if err != nil {
render.JSON(w, r, map[string]interface{}{"success": false, "errors": []string{err.Error()}})
return
}
render.JSON(w, r, map[string]interface{}{"feed": items, "success": true})
}
开发者ID:murdinc,项目名称:awsm,代码行数:29,代码来源:widgets.go
示例8: AddFeed
func AddFeed(writer http.ResponseWriter, req *http.Request) {
body, _ := ioutil.ReadAll(req.Body)
var objmap map[string]string
json.Unmarshal([]byte(body), &objmap)
var url = objmap["url"]
feed, err := rss.Fetch(url)
if err != nil {
fmt.Printf("Error fetching feed %s\n", err)
writer.WriteHeader(http.StatusInternalServerError)
return
}
err = db.Add(feed)
if err != nil {
fmt.Printf("%s\n", err)
writer.WriteHeader(http.StatusBadRequest)
return
}
writer.WriteHeader(http.StatusCreated)
jsonResult, _ := json.Marshal(feed)
fmt.Fprintf(writer, string(jsonResult))
}
开发者ID:henriwi,项目名称:gorss,代码行数:26,代码来源:api.go
示例9: init
func init() {
var err error
news, err = rss.Fetch("http://ranssi.paivola.fi/rss.php")
if err != nil {
log.Errorf("[Posts] Failed to load front-page posts: %s", err)
}
lastupdate = util.Timestamp()
}
开发者ID:tulir293,项目名称:ranssibot,代码行数:8,代码来源:util.go
示例10: fetchFeed
func fetchFeed(url string, ch chan *rss.Feed) {
fmt.Printf("Fetching %s \n", url)
feed, err := rss.Fetch(url)
if err != nil {
fmt.Println("Failed to get feed %s\n", url)
}
ch <- feed
}
开发者ID:enjoylife,项目名称:sec,代码行数:11,代码来源:main.go
示例11: GetRss
func GetRss(entry Entry) (to_scrape []Target) {
feed, err := rss.Fetch(entry.Url)
if err != nil {
fmt.Println("Entry:", entry.Name, "Error:", err)
} else {
for _, item := range feed.Items {
scrape_item := Target{item.Link, item.Title, entry.Language, item.Date}
to_scrape = append(to_scrape, scrape_item)
}
}
return
}
开发者ID:chilland,项目名称:go-scraper,代码行数:12,代码来源:scraper.go
示例12: checkFeed
func checkFeed(rssURL string) (newEntryArr []*feedEl, err error) {
if isFirstTime {
isFirstTime = false
_, err := rss.Fetch(rssURL)
if err != nil {
return nil, err
}
}
log.Println("Checking for new rss items...")
feed, err := rss.Fetch(rssURL)
if err != nil {
return nil, err
}
for _, e := range feed.Items {
newEntryArr = append(newEntryArr,
&feedEl{time: e.Date, title: e.Title, url: e.Link})
}
return
}
开发者ID:JAremko,项目名称:sc2tv.ru,代码行数:22,代码来源:rss.go
示例13: main
func main() {
if len(os.Args) == 1 {
fmt.Fprintf(os.Stderr, "Usage:\n\t%s [URL]\n", filepath.Base(os.Args[0]))
os.Exit(2)
}
feed, err := rss.Fetch(os.Args[1])
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", feed)
}
开发者ID:AlexanderThaller,项目名称:rss,代码行数:13,代码来源:debug.go
示例14: Search
func (c City) Search(category, query string) ([]Post, error) {
feed, err := rss.Fetch(fmt.Sprintf(searchCityStr, c.URL, category, query))
if err != nil {
fmt.Println(fmt.Sprintf(searchCityStr, c.URL, category, query))
return nil, err
}
results := make([]Post, 0)
for _, item := range feed.Items {
results = append(results, newPost(item))
}
return results, nil
}
开发者ID:i,项目名称:multicraig,代码行数:13,代码来源:search.go
示例15: Fetch
func (feed *Feed) Fetch() error {
var err error
logger.Info("Started fetching feed: %s", feed.Url)
rss.CacheParsedItemIDs(false)
feed.RawData, err = rss.Fetch(feed.Url)
if err != nil {
return err
}
logger.Info("Finished fetching feed: %s", feed.Url)
logger.Info("There are %d items in %s", len(feed.RawData.Items), feed.Url)
return nil
}
开发者ID:rastasheep,项目名称:utisak-worker,代码行数:14,代码来源:feed.go
示例16: Fetch
func Fetch(fn string) (*feed.Feed, error) {
fu, err := GetFeedUrl(fn)
if err != nil {
return nil, err
}
fn = fu
f, err := feed.Fetch(fn)
if err != nil {
return nil, err
}
return f, nil
}
开发者ID:heyLu,项目名称:lp,代码行数:14,代码来源:feeds.go
示例17: GetChinaNew
// 获取最新动态
func GetChinaNew() {
// 抓取rss
feed, err := rss.Fetch(chinaRss)
if err != nil {
return
}
err = feed.Update()
if err != nil {
return
}
// 循环每一项rss数据
FindInItem:
for k, _ := range feed.Items {
sego := controllers.SegoController{}
sentence := strings.TrimSpace(feed.Items[k].Title)
content := strings.TrimSpace(feed.Items[k].Content)
sentenceWords := sego.ToSlices(sentence, false)
contentWords := sego.ToSlices(content, false)
allWords := append(sentenceWords, contentWords...)
// 循环每个分词
for k, _ := range allWords {
// 查找城市
for m, _ := range citys {
// 省份、城市名逐个搜索
for p, _ := range citys[m] {
if allWords[k] == citys[m][p] {
// 情感分析
good, details, wordSlice := controllers.Scoring(sentence)
result := &models.YuqingResult{}
// 插入到结果表
result.Id = sentence
result.Category = m
result.Good = good
result.Detail = details
result.WordSlice = wordSlice
result.Insert()
continue FindInItem
}
}
}
}
}
}
开发者ID:treejames,项目名称:woku_old,代码行数:51,代码来源:china.go
示例18: updateNews
func updateNews() {
if news != nil {
err := news.Update()
if err != nil {
log.Errorf("[Posts] Failed to update front-page posts: %s", err)
}
} else {
var err error
news, err = rss.Fetch("http://ranssi.paivola.fi/rss.php")
if err != nil {
log.Errorf("[Posts] Failed to update front-page posts: %s", err)
}
}
lastupdate = util.Timestamp()
}
开发者ID:tulir293,项目名称:ranssibot,代码行数:15,代码来源:util.go
示例19: listenBuilds
func listenBuilds(lastMarker string, commandMsgs chan<- models.Message, connector models.Connector) (nextMarker string) {
var displayOnStart = 0
url := "https://" + connector.Login + ":" + connector.Pass + "@"
url += connector.Server + "/builds/plugins/servlet/streams?local=true"
feed, err := rss.Fetch(url)
if err != nil {
log.Print(err)
return
}
for i := len(feed.Items) - 1; i >= 0; i-- {
if connector.Debug {
log.Print("Bamboo " + connector.ID + " item #" + strconv.Itoa(i) + " marker " + feed.Items[i].Date.String())
}
if lastMarker == "" {
lastMarker = feed.Items[displayOnStart].Date.String()
}
item := feed.Items[i]
if item.Date.String() > lastMarker {
status := "NONE"
if strings.Contains(item.Title, "successful") {
status = "SUCCESS"
}
if strings.Contains(item.Title, "fail") {
status = "FAIL"
}
var m models.Message
m.In.ConnectorType = connector.Type
m.In.ConnectorID = connector.ID
m.In.Tags = connector.Tags
m.In.Process = false
m.Out.Text = "Bamboo Build " + html.UnescapeString(sanitize.HTML(item.Title))
m.Out.Detail = html.UnescapeString(sanitize.HTML(item.Content))
m.Out.Link = item.Link
m.Out.Status = status
commandMsgs <- m
if i == 0 {
lastMarker = item.Date.String()
}
}
}
nextMarker = lastMarker
return nextMarker
}
开发者ID:projectjane,项目名称:jane,代码行数:43,代码来源:bamboo.go
示例20: callRss
func callRss(lastMarker string, commandMsgs chan<- models.Message, connector models.Connector) (nextMarker string) {
var displayOnStart = 0
if connector.Debug {
log.Print("Starting rss feed fetch for " + connector.ID)
}
feed, err := rss.Fetch(connector.Server)
if err != nil {
log.Print(err)
return
}
if connector.Debug {
log.Print("Feed count for " + connector.ID + ": " + strconv.Itoa(len(feed.Items)))
}
for i := len(feed.Items) - 1; i >= 0; i-- {
if connector.Debug {
log.Print("Feed " + connector.ID + " item #" + strconv.Itoa(i) + " marker " + feed.Items[i].Date.String())
}
if lastMarker == "" {
lastMarker = feed.Items[displayOnStart].Date.String()
}
item := feed.Items[i]
if item.Date.String() > lastMarker {
var m models.Message
m.In.ConnectorType = connector.Type
m.In.ConnectorID = connector.ID
m.In.Tags = connector.Tags
m.In.Process = false
m.Out.Text = connector.ID + " " + html.UnescapeString(sanitize.HTML(item.Title))
m.Out.Detail = html.UnescapeString(sanitize.HTML(item.Content))
m.Out.Link = item.Link
commandMsgs <- m
if i == 0 {
lastMarker = item.Date.String()
}
}
}
nextMarker = lastMarker
if connector.Debug {
log.Print("Next marker for " + connector.ID + ": " + nextMarker)
}
return nextMarker
}
开发者ID:projectjane,项目名称:jane,代码行数:42,代码来源:rss.go
注:本文中的github.com/SlyMarbo/rss.Fetch函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论