Skip to content

Commit

Permalink
update to go mod
Browse files Browse the repository at this point in the history
fix charset error
  • Loading branch information
godcong committed Oct 9, 2018
1 parent a7f977c commit 284f5cf
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 77 deletions.
143 changes: 66 additions & 77 deletions charset.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package fate

import (
"log"
"strconv"
"strings"

"github.com/godcong/excavator"
"github.com/godcong/fate/debug"
"github.com/godcong/fate/model"
"github.com/satori/go.uuid"
)

type Charset []string

var (
Expand Down Expand Up @@ -645,89 +634,89 @@ var nameList = Charset{
}

func InitAll() {
model.CreateTables()
initCharFrom5156()
fixNameStrokes()
//model.CreateTables()
//initCharFrom5156()
//fixNameStrokes()
}

func initCharFrom5156() {
list := excavator.Get("http://xh.5156edu.com")
debug.Println("initCharFrom5156 start")
log.Println(list)
for k, v := range list {
insertCharacter(v, k)
}
debug.Println("initCharFrom5156 end")
//list := excavator.Get("http://xh.5156edu.com")
//debug.Println("initCharFrom5156 start")
//log.Println(list)
//for k, v := range list {
// insertCharacter(v, k)
//}
//debug.Println("initCharFrom5156 end")
}

func insertCharacter(charset Charset, k string) {
debug.Println("start: ", k)
for _, v := range charset {
s := strings.Split(v, "|")

s0, _ := strconv.Atoi(s[0])
if len(s) != 3 {
debug.Println("wrong:", s)
continue
}
c := model.Character{
SimpleStrokes: s0,
SimpleChar: s[1],
Pinyin: s[2],
Radical: k,
}
i, e := c.Create()
if e != nil {
debug.Println(i, e)
}
}
debug.Println("end", k)
//debug.Println("start: ", k)
//for _, v := range charset {
// s := strings.Split(v, "|")
//
// s0, _ := strconv.Atoi(s[0])
// if len(s) != 3 {
// debug.Println("wrong:", s)
// continue
// }
// c := model.Character{
// SimpleStrokes: s0,
// SimpleChar: s[1],
// Pinyin: s[2],
// Radical: k,
// }
// i, e := c.Create()
// if e != nil {
// debug.Println(i, e)
// }
//}
//debug.Println("end", k)

}

//delete because use kangxi dict
func updateStrokes() {
debug.Println("updateStrokes start")
for k, v := range scienceFixList {
ScienceUpdate(k, v)
}
debug.Println("updateStrokes end")
//debug.Println("updateStrokes start")
//for k, v := range scienceFixList {
// ScienceUpdate(k, v)
//}
//debug.Println("updateStrokes end")
}

func ScienceUpdate(index int, s string) {
debug.Println("science:", index)
sa := strings.Split(s, " ")
for _, v := range sa {
if v == "" {
continue
}
_ = v

c := model.Character{SimpleChar: v}
c = *c.Get()
c.ScienceStrokes = index
if uuid.FromStringOrNil(c.Id) == uuid.Nil {
debug.Println("notfound: ", c, v)
c.Create()
continue
}
c.Update()
}
//debug.Println("science:", index)
//sa := strings.Split(s, " ")
//for _, v := range sa {
// if v == "" {
// continue
// }
// _ = v
//
// c := model.Character{SimpleChar: v}
// c = *c.Get()
// c.ScienceStrokes = index
// if uuid.FromStringOrNil(c.Id) == uuid.Nil {
// debug.Println("notfound: ", c, v)
// c.Create()
// continue
// }
// c.Update()
//}

}

func fixNameStrokes() {
excavator.UpdateKangXi("http://tool.httpcn.com", func(detail excavator.CharDetail) {
log.Println(detail.Char)
c := model.Character{
SimpleChar: detail.Char,
}
c.Get()
c.NameType = detail.NameType
c.NameRoot = detail.NameRoot
c.ScienceStrokes = detail.ScienceStrokes
c.Update()

})
//excavator.UpdateKangXi("http://tool.httpcn.com", func(detail excavator.CharDetail) {
// log.Println(detail.Char)
// c := model.Character{
// SimpleChar: detail.Char,
// }
// c.Get()
// c.NameType = detail.NameType
// c.NameRoot = detail.NameRoot
// c.ScienceStrokes = detail.ScienceStrokes
// c.Update()
//
//})

}
22 changes: 22 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module github.com/godcong/fate

require (
cloud.google.com/go v0.30.0 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/denisenkom/go-mssqldb v0.0.0-20180901172138-1eb28afdf9b6 // indirect
github.com/go-sql-driver/mysql v1.3.0
github.com/go-xorm/builder v0.0.0-20171030021429-a4a881a4e552 // indirect
github.com/go-xorm/core v0.5.7 // indirect
github.com/go-xorm/xorm v0.6.4
github.com/google/go-cmp v0.2.0 // indirect
github.com/lib/pq v1.0.0 // indirect
github.com/mattn/go-sqlite3 v1.1.0
github.com/pelletier/go-toml v1.0.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/satori/go.uuid v1.1.0
github.com/stretchr/testify v1.2.2 // indirect
github.com/ziutek/mymysql v1.5.4 // indirect
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 // indirect
gopkg.in/yaml.v2 v2.2.1 // indirect
)
38 changes: 38 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cloud.google.com/go v0.30.0 h1:xKvyLgk56d0nksWq49J0UyGEeUIicTl4+UBiX1NPX9g=
cloud.google.com/go v0.30.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20180901172138-1eb28afdf9b6 h1:BZGp1dbKFjqlGmxEpwkDpCWNxVwEYnUPoncIzLiHlPo=
github.com/denisenkom/go-mssqldb v0.0.0-20180901172138-1eb28afdf9b6/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc=
github.com/go-sql-driver/mysql v1.3.0 h1:pgwjLi/dvffoP9aabwkT3AKpXQM93QARkjFhDDqC1UE=
github.com/go-sql-driver/mysql v1.3.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-xorm/builder v0.0.0-20171030021429-a4a881a4e552 h1:/TkKpYxAhQLO5NplNx9pf6ne3HK9zaL5oJKBxsazzhY=
github.com/go-xorm/builder v0.0.0-20171030021429-a4a881a4e552/go.mod h1:M+P3wv0K2C+ynucGDEqJCeOTc+6DcAtiiqU8GrCksXY=
github.com/go-xorm/core v0.5.7 h1:ClaJQDjHDre5Yco2MmkWKniM8NNdC/OXmoy2HfxxECw=
github.com/go-xorm/core v0.5.7/go.mod h1:i7QESCABdFcvhgc8pdINtzlJf/6LC29if6ZJgHt9SHI=
github.com/go-xorm/xorm v0.6.4 h1:J0X2FjXl6voshSZj91iYPuLsXfvrKJ9NB+Bpq0/kDBc=
github.com/go-xorm/xorm v0.6.4/go.mod h1:i7qRPD38xj/v75UV+a9pEzr5tfRaH2ndJfwt/fGbQhs=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-sqlite3 v1.1.0 h1:uggQm4+cc4c0du7NMV5XaXTnHRd0Zx9KMCT6csVT6ZI=
github.com/mattn/go-sqlite3 v1.1.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/pelletier/go-toml v1.0.1 h1:0nx4vKBl23+hEaCOV1mFhKS9vhhBtFYWC7rQY0vJAyE=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/satori/go.uuid v1.1.0 h1:B9KXyj+GzIpJbV7gmr873NsY6zpbxNy24CBtGrk7jHo=
github.com/satori/go.uuid v1.1.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 h1:Vk3wNqEZwyGyei9yq5ekj7frek2u7HUfffJ1/opblzc=
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit 284f5cf

Please sign in to comment.