aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/importer/ACDv2Reader.go8
-rw-r--r--tools/importer/main.go23
2 files changed, 31 insertions, 0 deletions
diff --git a/tools/importer/ACDv2Reader.go b/tools/importer/ACDv2Reader.go
index 974da52..4dab3c0 100644
--- a/tools/importer/ACDv2Reader.go
+++ b/tools/importer/ACDv2Reader.go
@@ -7,6 +7,7 @@ import (
7 "strings" 7 "strings"
8 8
9 "fagott.pw/grilist/modules/grils" 9 "fagott.pw/grilist/modules/grils"
10 "fagott.pw/grilist/modules/series"
10) 11)
11 12
12const failMsg = "Offenbar war meine Annahme bzgl. der Traits nicht ganz korrekt" 13const failMsg = "Offenbar war meine Annahme bzgl. der Traits nicht ganz korrekt"
@@ -75,6 +76,13 @@ func (r *ACDv2Reader) Read(path string) WrappedGril {
75 } 76 }
76 g.Gril.Traits = append(g.Gril.Traits, t) 77 g.Gril.Traits = append(g.Gril.Traits, t)
77 } 78 }
79 g.Gril.Series = make([]series.Series, 0)
80 for _, v := range jObj.Assignments {
81 s := series.Series{
82 ID: v,
83 }
84 g.Gril.Series = append(g.Gril.Series, s)
85 }
78 return g 86 return g
79} 87}
80 88
diff --git a/tools/importer/main.go b/tools/importer/main.go
index fd7af37..4eba9a0 100644
--- a/tools/importer/main.go
+++ b/tools/importer/main.go
@@ -179,6 +179,28 @@ func InsertTraits(dbID int, g WrappedGril, traitlist map[string]int) {
179 LogErr(err) 179 LogErr(err)
180 } 180 }
181} 181}
182
183func InsertSeries(dbID int, g WrappedGril) {
184 rows, err := db.Query("SELECT appearance_id FROM grils_appearances WHERE gril_id = $1;", dbID)
185 LogErr(err)
186 existingSeries := make(map[int]bool, 0)
187 for rows.Next() {
188 var seriesID int
189 rows.Scan(&seriesID)
190 existingSeries[seriesID] = true
191 }
192 for _, v := range g.Gril.Series {
193 if _, ok := existingSeries[v.ID]; ok {
194 continue
195 }
196 _, err := db.Exec("INSERT INTO grilist.grils_appearances (gril_id, appearance_id) VALUES ($1, $2);",
197 dbID, v.ID)
198 existingSeries[v.ID] = true
199 fmt.Printf("Assigned series %d to %s\n", v.ID, g.Gril.RomajiName)
200 LogErr(err)
201 }
202}
203
182func main() { 204func main() {
183 flag.StringVar(&path, "path", "", "path of the source files") 205 flag.StringVar(&path, "path", "", "path of the source files")
184 flag.StringVar(&sourceType, "type", "", "type of the files (ACD, AniDB)") 206 flag.StringVar(&sourceType, "type", "", "type of the files (ACD, AniDB)")
@@ -252,6 +274,7 @@ func main() {
252 } 274 }
253 InsertTags(dbID, g, taglist) 275 InsertTags(dbID, g, taglist)
254 InsertTraits(dbID, g, traitlist) 276 InsertTraits(dbID, g, traitlist)
277 InsertSeries(dbID, g)
255 278
256 return nil 279 return nil
257 }) 280 })