This commit is contained in:
parent
aa45c0589a
commit
6d0b9e35a1
@ -30,9 +30,7 @@ func (config *Config) GetConfig() error {
|
||||
config.DbPassword = qrzsection.Key("db_password").MustString("password")
|
||||
config.DbSchema = qrzsection.Key("db_schema").MustString("")
|
||||
config.DbTable = qrzsection.Key("db_table").MustString("qrz")
|
||||
config.FrsConfig.URL = qrzsection.Key("frs_url").MustString("")
|
||||
config.FrsConfig.XPath = qrzsection.Key("frs_xpath").MustString("//tr")
|
||||
config.FrsConfig.Regex = qrzsection.Key("frs_regex").MustString(".*")
|
||||
config.FrsConfig.URL = qrzsection.Key("frs_url").MustString("http://groupe-frs.hamstation.eu/index_qrz_liste_14.htm")
|
||||
|
||||
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)
|
||||
|
||||
@ -59,8 +57,6 @@ type Config struct {
|
||||
DbCheck string
|
||||
}
|
||||
FrsConfig struct {
|
||||
URL string
|
||||
XPath string
|
||||
Regex string
|
||||
URL string
|
||||
}
|
||||
}
|
||||
|
@ -38,14 +38,14 @@ func GetBody(config config.Config) (string, error) {
|
||||
// GetFrsEntries get FRS entries from html body
|
||||
func GetFrsEntries(config config.Config, body string) (frsentries map[string]FrsEntry, err error) {
|
||||
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))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, n := range htmlquery.Find(htmlpage, config.FrsConfig.XPath) {
|
||||
for _, n := range htmlquery.Find(htmlpage, "//tr") {
|
||||
td := htmlquery.Find(n, "//td")
|
||||
if re.MatchString(htmlquery.InnerText(td[0])) {
|
||||
frs := FrsEntry{
|
||||
|
Loading…
Reference in New Issue
Block a user