diff options
| author | rtz12 <koenig@fagott.pw> | 2016-10-02 02:59:08 (UTC) |
|---|---|---|
| committer | rtz12 <koenig@fagott.pw> | 2016-10-02 02:59:08 (UTC) |
| commit | 5997487fc5cc2126fb5afa12b75b67f3985e11d2 (patch) | |
| tree | d0631885961a35daf7ec302161ea888ae02183aa /tools/importer/ACDv2Reader.go | |
| parent | b799217c66df7c1c4ef285699273a5222efccfb0 (diff) | |
Importer etwas netter strukturiert und Support fuer die neuen ACD-Daten
hinzugefuegt
Diffstat (limited to 'tools/importer/ACDv2Reader.go')
| -rw-r--r-- | tools/importer/ACDv2Reader.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/importer/ACDv2Reader.go b/tools/importer/ACDv2Reader.go new file mode 100644 index 0000000..2ddca4d --- /dev/null +++ b/tools/importer/ACDv2Reader.go | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "encoding/json" | ||
| 5 | "io/ioutil" | ||
| 6 | "path/filepath" | ||
| 7 | "strings" | ||
| 8 | |||
| 9 | "fagott.pw/grilist/modules/grils" | ||
| 10 | ) | ||
| 11 | |||
| 12 | type ACDv2Reader struct{} | ||
| 13 | |||
| 14 | type ACDv2NameValue struct { | ||
| 15 | Name string `json:"name"` | ||
| 16 | Value string `json:"value"` | ||
| 17 | } | ||
| 18 | |||
| 19 | type ACDv2Gril struct { | ||
| 20 | Name struct { | ||
| 21 | Romaji string `json:"romaji"` | ||
| 22 | Japanese string `json:"japanese"` | ||
| 23 | Aliases []string `json:"aliases"` | ||
| 24 | } `json:"name"` | ||
| 25 | Image struct { | ||
| 26 | Thumbnail string `json:"thumb"` | ||
| 27 | Full string `json:"full"` | ||
| 28 | } `json:"image"` | ||
| 29 | Tags []struct { | ||
| 30 | ID int `json:"id"` | ||
| 31 | Name string `json:"name"` | ||
| 32 | } `json:"tags"` | ||
| 33 | Traits struct { | ||
| 34 | Official []ACDv2NameValue `json:"official"` | ||
| 35 | Indexed []ACDv2NameValue `json:"indexed"` | ||
| 36 | } `json:"traits"` | ||
| 37 | Assignments []int `json:"assignments"` | ||
| 38 | CharsWithSimilarTraits []int `json:"chars_similar_traits"` | ||
| 39 | Extra []ACDv2NameValue `json:"extra"` | ||
| 40 | Role string `json:"role"` | ||
| 41 | } | ||
| 42 | |||
| 43 | func (r *ACDv2Reader) Read(path string) WrappedGril { | ||
| 44 | g := WrappedGril{} | ||
| 45 | g.Gril = grils.Gril{} | ||
| 46 | data, err := ioutil.ReadFile(path) | ||
| 47 | ifErrExit(err) | ||
| 48 | var jObj ACDv2Gril | ||
| 49 | err = json.Unmarshal(data, &jObj) | ||
| 50 | ifErrExit(err) | ||
| 51 | g.Image = jObj.Image.Full | ||
| 52 | g.Thumb = jObj.Image.Thumbnail | ||
| 53 | g.Gril.ID = toInt(strings.TrimSuffix(filepath.Base(path), ".json")) | ||
| 54 | g.Gril.KanjiName = jObj.Name.Japanese | ||
| 55 | g.Gril.RomajiName = jObj.Name.Romaji | ||
| 56 | g.Gril.OtherNames = jObj.Name.Aliases | ||
| 57 | g.Gril.Tags = make([]string, 0) | ||
| 58 | for _, v := range jObj.Tags { | ||
| 59 | g.Gril.Tags = append(g.Gril.Tags, v.Name) | ||
| 60 | } | ||
| 61 | return g | ||
| 62 | } | ||
| 63 | |||
| 64 | func (r *ACDv2Reader) ID() int { | ||
| 65 | return int(grils.DataSourceACD) | ||
| 66 | } | ||
