updated structs in qrz
This commit is contained in:
parent
f87f436891
commit
6e1edf9e1c
@ -36,27 +36,29 @@ func (config *Config) GetConfig() error {
|
|||||||
|
|
||||||
config.DbSchema = fmt.Sprintf("CREATE TABLE IF NOT EXISTS `%s` (`id` int(8) NOT NULL AUTO_INCREMENT, `qrz` varchar(25) NOT NULL, `name` varchar(25) DEFAULT NULL, `address` varchar(50) DEFAULT NULL, `city` varchar(50) DEFAULT NULL, `zipcode` varchar(5) DEFAULT NULL, `dept` varchar(50) DEFAULT NULL, `country` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `qrz` (`qrz`,`name`,`city`,`dept`) USING BTREE, KEY `test` (`country`), FULLTEXT KEY `city` (`city`), FULLTEXT KEY `dept` (`dept`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;", config.DbTable)
|
config.DbSchema = fmt.Sprintf("CREATE TABLE IF NOT EXISTS `%s` (`id` int(8) NOT NULL AUTO_INCREMENT, `qrz` varchar(25) NOT NULL, `name` varchar(25) DEFAULT NULL, `address` varchar(50) DEFAULT NULL, `city` varchar(50) DEFAULT NULL, `zipcode` varchar(5) DEFAULT NULL, `dept` varchar(50) DEFAULT NULL, `country` varchar(25) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `qrz` (`qrz`,`name`,`city`,`dept`) USING BTREE, KEY `test` (`country`), FULLTEXT KEY `city` (`city`), FULLTEXT KEY `dept` (`dept`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;", config.DbTable)
|
||||||
|
|
||||||
config.DbInsertStatement = "INSERT IGNORE INTO %s (qrz,name,city,dept,country) VALUES ('%s','%s','%s','%s','%s');"
|
config.Statements.DbInsert = "INSERT IGNORE INTO %s (qrz,name,city,dept,country) VALUES ('%s','%s','%s','%s','%s');"
|
||||||
|
|
||||||
config.DbGetQrzStatement = "SELECT qrz FROM %s;"
|
config.Statements.DbGetQrz = "SELECT qrz FROM %s;"
|
||||||
|
|
||||||
config.DbCheckStatement = "SELECT COUNT(*) FROM %s WHERE qrz = '%s';"
|
config.Statements.DbCheck = "SELECT COUNT(*) FROM %s WHERE qrz = '%s';"
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is the global config of g2g
|
// Config is the global config of g2g
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DbHostname string
|
DbHostname string
|
||||||
DbName string
|
DbName string
|
||||||
DbUsername string
|
DbUsername string
|
||||||
DbPassword string
|
DbPassword string
|
||||||
DbSchema string
|
DbSchema string
|
||||||
DbTable string
|
DbTable string
|
||||||
DbInsertStatement string
|
Statements struct {
|
||||||
DbGetQrzStatement string
|
DbInsert string
|
||||||
DbCheckStatement string
|
DbGetQrz string
|
||||||
FrsConfig struct {
|
DbCheck string
|
||||||
|
}
|
||||||
|
FrsConfig struct {
|
||||||
URL string
|
URL string
|
||||||
XPath string
|
XPath string
|
||||||
Regex string
|
Regex string
|
||||||
|
@ -57,12 +57,13 @@ func GetFrsEntries(config config.Config, body string) (frsentries map[string]Frs
|
|||||||
frsentries[frs.QRZ] = frs
|
frsentries[frs.QRZ] = frs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentEntries fetch existing entries from database
|
// GetCurrentEntries fetch existing entries from database
|
||||||
func GetCurrentEntries(config config.Config, db sqlx.DB) (existingQRZ []string, err error) {
|
func GetCurrentEntries(config config.Config, db sqlx.DB) (existingQRZ []string, err error) {
|
||||||
q := fmt.Sprintf(config.DbGetQrzStatement, config.DbTable)
|
q := fmt.Sprintf(config.Statements.DbGetQrz, config.DbTable)
|
||||||
rows, err := db.Query(q)
|
rows, err := db.Query(q)
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@ -79,6 +80,7 @@ func DiscardExistingEntries(config config.Config, frsPeople *map[string]FrsEntry
|
|||||||
for _, entry := range existingQRZ {
|
for _, entry := range existingQRZ {
|
||||||
delete(*frsPeople, entry)
|
delete(*frsPeople, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ func InsertFrsEntryToDB(config config.Config, db sqlx.DB, frsPeople map[string]F
|
|||||||
fmt.Println(fmt.Sprintf("Starting inserts of %d entries", len(frsPeople)))
|
fmt.Println(fmt.Sprintf("Starting inserts of %d entries", len(frsPeople)))
|
||||||
|
|
||||||
for _, j := range frsPeople {
|
for _, j := range frsPeople {
|
||||||
query := fmt.Sprintf(config.DbInsertStatement, config.DbTable, j.QRZ, j.Name, j.City, j.Dept, j.Country)
|
query := fmt.Sprintf(config.Statements.DbInsert, config.DbTable, j.QRZ, j.Name, j.City, j.Dept, j.Country)
|
||||||
tx.MustExec(query)
|
tx.MustExec(query)
|
||||||
qrzNum++
|
qrzNum++
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user