From 99ce3d4d3b06d735206fbd4ed4946dbd7b8c6419 Mon Sep 17 00:00:00 2001 From: rtz12 Date: Sun, 9 Oct 2016 17:27:29 +0200 Subject: Serienverknuepfung hinzugefuegt diff --git a/modules/grils/gril.go b/modules/grils/gril.go index edec05a..0462e86 100644 --- a/modules/grils/gril.go +++ b/modules/grils/gril.go @@ -8,6 +8,8 @@ import ( "strings" "time" + "fagott.pw/grilist/modules/series" + "github.com/lib/pq" ) @@ -37,6 +39,7 @@ type Gril struct { ForeignIDs map[DataSource]int UpdatedAt time.Time Lists []int + Series []series.Series } func (g *Gril) Slug() string { 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 ( "strings" "fagott.pw/grilist/modules/grils" + "fagott.pw/grilist/modules/series" ) const failMsg = "Offenbar war meine Annahme bzgl. der Traits nicht ganz korrekt" @@ -75,6 +76,13 @@ func (r *ACDv2Reader) Read(path string) WrappedGril { } g.Gril.Traits = append(g.Gril.Traits, t) } + g.Gril.Series = make([]series.Series, 0) + for _, v := range jObj.Assignments { + s := series.Series{ + ID: v, + } + g.Gril.Series = append(g.Gril.Series, s) + } return g } 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) { LogErr(err) } } + +func InsertSeries(dbID int, g WrappedGril) { + rows, err := db.Query("SELECT appearance_id FROM grils_appearances WHERE gril_id = $1;", dbID) + LogErr(err) + existingSeries := make(map[int]bool, 0) + for rows.Next() { + var seriesID int + rows.Scan(&seriesID) + existingSeries[seriesID] = true + } + for _, v := range g.Gril.Series { + if _, ok := existingSeries[v.ID]; ok { + continue + } + _, err := db.Exec("INSERT INTO grilist.grils_appearances (gril_id, appearance_id) VALUES ($1, $2);", + dbID, v.ID) + existingSeries[v.ID] = true + fmt.Printf("Assigned series %d to %s\n", v.ID, g.Gril.RomajiName) + LogErr(err) + } +} + func main() { flag.StringVar(&path, "path", "", "path of the source files") flag.StringVar(&sourceType, "type", "", "type of the files (ACD, AniDB)") @@ -252,6 +274,7 @@ func main() { } InsertTags(dbID, g, taglist) InsertTraits(dbID, g, traitlist) + InsertSeries(dbID, g) return nil }) -- cgit v0.10.1