-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 977 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
49
50
51
52
package main
import (
"github.com/hamza72x/islamqa-scrapper/content"
"github.com/hamza72x/islamqa-scrapper/log"
"github.com/hamza72x/islamqa-scrapper/scrapper"
"github.com/hamza72x/islamqa-scrapper/sitemap"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func main() {
log.Initialize()
// open database
db, err := gorm.Open(sqlite.Open("local.db"), &gorm.Config{})
if err != nil {
log.Fatal("failed to connect database: " + err.Error())
}
// migrate
if err := db.AutoMigrate(
&sitemap.URL{},
&content.Content{},
&content.ContentV2{},
); err != nil {
log.Fatal("failed to migrate database: " + err.Error())
}
// create scrapper
s := scrapper.New(db)
// sync sitemaps
errs := s.SyncSitemaps(siteMaps)
if len(errs) > 0 {
for _, err := range errs {
log.Err(err)
}
}
// // sync conents
// if err := s.SyncContents(); err != nil {
// log.Err(err)
// }
// sync conents v2
if err := s.SyncContentsV2(); err != nil {
log.Err(err)
}
}