45 lines
663 B
Go
45 lines
663 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/mmcdole/gofeed"
|
|
)
|
|
|
|
func fileGet(filepath, url string) (err error) {
|
|
out, err := os.Create(filepath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer out.Close()
|
|
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
_, err = io.Copy(out, resp.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
feedParser := gofeed.NewParser()
|
|
feed, _ := feedParser.ParseURL("http://feeds.twit.tv/twit.xml")
|
|
|
|
fileUrl := feed.Items[1].Enclosures[0].URL
|
|
fileTitle := feed.Items[1].Title
|
|
|
|
fmt.Println(fileUrl)
|
|
fmt.Println(fileTitle)
|
|
|
|
fileGet(fileTitle, fileUrl)
|
|
}
|