updated qrz
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2020-04-10 01:12:37 +02:00
parent aa45c0589a
commit 6d0b9e35a1
2 changed files with 4 additions and 8 deletions

View File

@ -30,9 +30,7 @@ func (config *Config) GetConfig() error {
config.DbPassword = qrzsection.Key("db_password").MustString("password") config.DbPassword = qrzsection.Key("db_password").MustString("password")
config.DbSchema = qrzsection.Key("db_schema").MustString("") config.DbSchema = qrzsection.Key("db_schema").MustString("")
config.DbTable = qrzsection.Key("db_table").MustString("qrz") config.DbTable = qrzsection.Key("db_table").MustString("qrz")
config.FrsConfig.URL = qrzsection.Key("frs_url").MustString("") config.FrsConfig.URL = qrzsection.Key("frs_url").MustString("http://groupe-frs.hamstation.eu/index_qrz_liste_14.htm")
config.FrsConfig.XPath = qrzsection.Key("frs_xpath").MustString("//tr")
config.FrsConfig.Regex = qrzsection.Key("frs_regex").MustString(".*")
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)
@ -60,7 +58,5 @@ type Config struct {
} }
FrsConfig struct { FrsConfig struct {
URL string URL string
XPath string
Regex string
} }
} }

View File

@ -38,14 +38,14 @@ func GetBody(config config.Config) (string, error) {
// GetFrsEntries get FRS entries from html body // GetFrsEntries get FRS entries from html body
func GetFrsEntries(config config.Config, body string) (frsentries map[string]FrsEntry, err error) { func GetFrsEntries(config config.Config, body string) (frsentries map[string]FrsEntry, err error) {
frsentries = make(map[string]FrsEntry) frsentries = make(map[string]FrsEntry)
re := regexp.MustCompile(config.FrsConfig.Regex) re := regexp.MustCompile(`^[0-9]{1,4}\s[A-Z]{1,4}\s[0-9]{1,4}`)
htmlpage, err := htmlquery.Parse(strings.NewReader(body)) htmlpage, err := htmlquery.Parse(strings.NewReader(body))
if err != nil { if err != nil {
return return
} }
for _, n := range htmlquery.Find(htmlpage, config.FrsConfig.XPath) { for _, n := range htmlquery.Find(htmlpage, "//tr") {
td := htmlquery.Find(n, "//td") td := htmlquery.Find(n, "//td")
if re.MatchString(htmlquery.InnerText(td[0])) { if re.MatchString(htmlquery.InnerText(td[0])) {
frs := FrsEntry{ frs := FrsEntry{