-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 969 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"log"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
func main() {
db, dbErr := gorm.Open("sqlite3", "./sqlite3.db")
defer db.Close()
// db = db.Debug()
if dbErr != nil {
log.Fatal(dbErr)
}
ktotonepravURL := "https://www.youtube.com/feeds/videos.xml?channel_id=UCWfRKs8owsEkERlwO1uwOFw"
feed, parsErr := readRSS(&ktotonepravURL)
if parsErr != nil {
log.Fatal(parsErr.Error())
}
db.AutoMigrate(&Author{}, &Episode{}, &Category{}, &Podcast{})
for _, cat := range fillCategories() {
if db.NewRecord(cat) {
db.Create(&cat)
}
}
parsedPod := parseYtRss(feed)
db.Create(&parsedPod)
var selectedPod Podcast
db.Preload("Episodes", func(db *gorm.DB) *gorm.DB {
return db.Order("id ASC")
}).Preload("Categories").Last(&selectedPod)
itcPod := itcPodcastFrom(&selectedPod)
writErr := writeItunesPodcastRssXML(itcPod)
if writErr != nil {
log.Fatal(writErr)
}
runWebServer(selectedPod)
}