rss image

main
ColumbusUtrigas 2022-08-21 08:14:24 +04:00
parent c7103d04ad
commit 1c0fc3345e
2 changed files with 16 additions and 3 deletions

15
app.go
View File

@ -25,6 +25,7 @@ type Parser interface {
Title() string
Description() string
RootUrl() string
ImageUrl() string
ServerUrl() string
CacheName() string
CacheTimeout() int
@ -65,6 +66,11 @@ func (this *ParserFeed) ParseAndUpdateCache() {
Link: &feeds.Link{Href: this.parser.RootUrl()},
Description: this.parser.Description(),
Created: time.Now(),
Image: &feeds.Image{
Url: this.parser.ImageUrl(),
Title: this.parser.Title(),
Link: this.parser.RootUrl(),
},
}
entities := this.parser.Parse()
@ -74,7 +80,7 @@ func (this *ParserFeed) ParseAndUpdateCache() {
Id: re.url,
Title: re.title,
Link: &feeds.Link{Href: re.url},
Description: re.title,
Description: re.descripiton,
Created: time.Now(),
})
}
@ -102,13 +108,11 @@ func (this *ParserFeed) RunWorker() {
for {
nextmark := this.time.Add(time.Second * time.Duration(this.parser.CacheTimeout()))
sleepfor := nextmark.Unix() - time.Now().Unix()
fmt.Println(sleepfor)
if sleepfor > 0 {
time.Sleep(time.Second * time.Duration(sleepfor))
}
this.ParseAndUpdateCache()
fmt.Println("update")
}
}
@ -152,6 +156,11 @@ func main() {
rootPage += "</body></html>"
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
w.WriteHeader(404)
return
}
fmt.Fprintf(w, rootPage)
})

View File

@ -64,6 +64,10 @@ func (this NvidiaParser) RootUrl() string {
return "https://research.nvidia.com"
}
func (this NvidiaParser) ImageUrl() string {
return this.RootUrl() + "/themes/custom/nvidia/favicon.ico"
}
func (this NvidiaParser) ServerUrl() string {
return "/nvidia"
}