rss image
parent
c7103d04ad
commit
1c0fc3345e
15
app.go
15
app.go
|
|
@ -25,6 +25,7 @@ type Parser interface {
|
||||||
Title() string
|
Title() string
|
||||||
Description() string
|
Description() string
|
||||||
RootUrl() string
|
RootUrl() string
|
||||||
|
ImageUrl() string
|
||||||
ServerUrl() string
|
ServerUrl() string
|
||||||
CacheName() string
|
CacheName() string
|
||||||
CacheTimeout() int
|
CacheTimeout() int
|
||||||
|
|
@ -65,6 +66,11 @@ func (this *ParserFeed) ParseAndUpdateCache() {
|
||||||
Link: &feeds.Link{Href: this.parser.RootUrl()},
|
Link: &feeds.Link{Href: this.parser.RootUrl()},
|
||||||
Description: this.parser.Description(),
|
Description: this.parser.Description(),
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
|
Image: &feeds.Image{
|
||||||
|
Url: this.parser.ImageUrl(),
|
||||||
|
Title: this.parser.Title(),
|
||||||
|
Link: this.parser.RootUrl(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
entities := this.parser.Parse()
|
entities := this.parser.Parse()
|
||||||
|
|
@ -74,7 +80,7 @@ func (this *ParserFeed) ParseAndUpdateCache() {
|
||||||
Id: re.url,
|
Id: re.url,
|
||||||
Title: re.title,
|
Title: re.title,
|
||||||
Link: &feeds.Link{Href: re.url},
|
Link: &feeds.Link{Href: re.url},
|
||||||
Description: re.title,
|
Description: re.descripiton,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -102,13 +108,11 @@ func (this *ParserFeed) RunWorker() {
|
||||||
for {
|
for {
|
||||||
nextmark := this.time.Add(time.Second * time.Duration(this.parser.CacheTimeout()))
|
nextmark := this.time.Add(time.Second * time.Duration(this.parser.CacheTimeout()))
|
||||||
sleepfor := nextmark.Unix() - time.Now().Unix()
|
sleepfor := nextmark.Unix() - time.Now().Unix()
|
||||||
fmt.Println(sleepfor)
|
|
||||||
|
|
||||||
if sleepfor > 0 {
|
if sleepfor > 0 {
|
||||||
time.Sleep(time.Second * time.Duration(sleepfor))
|
time.Sleep(time.Second * time.Duration(sleepfor))
|
||||||
}
|
}
|
||||||
this.ParseAndUpdateCache()
|
this.ParseAndUpdateCache()
|
||||||
fmt.Println("update")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,6 +156,11 @@ func main() {
|
||||||
rootPage += "</body></html>"
|
rootPage += "</body></html>"
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.URL.Path != "/" {
|
||||||
|
w.WriteHeader(404)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, rootPage)
|
fmt.Fprintf(w, rootPage)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ func (this NvidiaParser) RootUrl() string {
|
||||||
return "https://research.nvidia.com"
|
return "https://research.nvidia.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this NvidiaParser) ImageUrl() string {
|
||||||
|
return this.RootUrl() + "/themes/custom/nvidia/favicon.ico"
|
||||||
|
}
|
||||||
|
|
||||||
func (this NvidiaParser) ServerUrl() string {
|
func (this NvidiaParser) ServerUrl() string {
|
||||||
return "/nvidia"
|
return "/nvidia"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue