aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/importer/main.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/tools/importer/main.go b/tools/importer/main.go
index 4eba9a0..8c60ef7 100644
--- a/tools/importer/main.go
+++ b/tools/importer/main.go
@@ -180,7 +180,7 @@ func InsertTraits(dbID int, g WrappedGril, traitlist map[string]int) {
180 } 180 }
181} 181}
182 182
183func InsertSeries(dbID int, g WrappedGril) { 183func InsertSeries(dbID int, g WrappedGril, seriesmap map[int]int) {
184 rows, err := db.Query("SELECT appearance_id FROM grils_appearances WHERE gril_id = $1;", dbID) 184 rows, err := db.Query("SELECT appearance_id FROM grils_appearances WHERE gril_id = $1;", dbID)
185 LogErr(err) 185 LogErr(err)
186 existingSeries := make(map[int]bool, 0) 186 existingSeries := make(map[int]bool, 0)
@@ -190,13 +190,17 @@ func InsertSeries(dbID int, g WrappedGril) {
190 existingSeries[seriesID] = true 190 existingSeries[seriesID] = true
191 } 191 }
192 for _, v := range g.Gril.Series { 192 for _, v := range g.Gril.Series {
193 if _, ok := existingSeries[v.ID]; ok { 193 seriesID, ok := seriesmap[v.ID]
194 if !ok {
195 panic(fmt.Sprintf("Could not find series %s! Did you import the series?", v.ID))
196 }
197 if _, ok := existingSeries[seriesID]; ok {
194 continue 198 continue
195 } 199 }
196 _, err := db.Exec("INSERT INTO grilist.grils_appearances (gril_id, appearance_id) VALUES ($1, $2);", 200 _, err := db.Exec("INSERT INTO grilist.grils_appearances (gril_id, appearance_id) VALUES ($1, $2);",
197 dbID, v.ID) 201 dbID, seriesID)
198 existingSeries[v.ID] = true 202 existingSeries[seriesID] = true
199 fmt.Printf("Assigned series %d to %s\n", v.ID, g.Gril.RomajiName) 203 fmt.Printf("Assigned series %d to %s\n", seriesID, g.Gril.RomajiName)
200 LogErr(err) 204 LogErr(err)
201 } 205 }
202} 206}
@@ -261,6 +265,14 @@ func main() {
261 rows.Scan(&sourceID, &grilID) 265 rows.Scan(&sourceID, &grilID)
262 idmap[sourceID] = grilID 266 idmap[sourceID] = grilID
263 } 267 }
268 seriesmap := make(map[int]int)
269 rows, _ = db.Query("SELECT appearance_id, source_id FROM grilist.appearances_id_mappings WHERE source = $1", r.ID())
270 for rows.Next() {
271 var seriesID int
272 var sourceID int
273 rows.Scan(&seriesID, &sourceID)
274 seriesmap[sourceID] = seriesID
275 }
264 276
265 filepath.Walk(path, func(path string, info os.FileInfo, err error) error { 277 filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
266 if info.IsDir() { 278 if info.IsDir() {
@@ -274,7 +286,7 @@ func main() {
274 } 286 }
275 InsertTags(dbID, g, taglist) 287 InsertTags(dbID, g, taglist)
276 InsertTraits(dbID, g, traitlist) 288 InsertTraits(dbID, g, traitlist)
277 InsertSeries(dbID, g) 289 InsertSeries(dbID, g, seriesmap)
278 290
279 return nil 291 return nil
280 }) 292 })