add nmcprovince

master
hwf452 9 months ago
parent 276e6e9715
commit e17b848ca2

@ -2,7 +2,7 @@ appname = weather
ServerName = "beego"
#runmode = dev
runmode = prod
httpport = 8082
httpport = 8084
#mysqluser = "root"
#mysqlpass = "Skyinno251,"
#mysqlurls = "192.168.5.21:3306"
@ -15,7 +15,8 @@ httpport = 8082
SessionName = "beegosessionID"
syncFrequency = "0 */10 * * * *"
syncFrequencyWeather = "0 16 * * * *"
# syncFrequencyWeather = "0 16 * * * *"
syncFrequencyWeather = "*/10 * * * * *"
mysqluser = "root"

@ -17,10 +17,22 @@ func init() {
orm.RegisterModel(new(NmcProvince))
}
func NmcProvinceAdd(item *NmcProvince) (int64, error) {
return orm.NewOrm().Insert(item)
}
func GetNmcProvince(item *NmcProvince) bool {
var nmcProvinceTemp NmcProvince
o := orm.NewOrm()
err := o.QueryTable(new(NmcProvince)).Filter("code", item.Code).One(&nmcProvinceTemp)
if err == nil {
return true
}
return false
}
func GetNmcProvinceList() []*NmcProvince {
items := make([]*NmcProvince, 0)
orm.NewOrm().QueryTable(new(NmcCity)).All(&items)
return items
}

@ -1,6 +1,7 @@
package service
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/httplib"
"strconv"
@ -13,6 +14,36 @@ type HttpWeatherService struct {
}
func SyncNmcCityAndNmcProvince() {
timeUnix := time.Now().Unix()
s := strconv.FormatInt(timeUnix, 10)
url := "http://www.nmc.cn/rest/province/all?_=" + s + "000"
//http://www.nmc.cn/rest/province/all?_=1741052160653
//http://www.nmc.cn/rest/province/all?_=1741052160653
fmt.Println(url)
req := httplib.Get(url)
provinceListJson, err := req.String()
if err != nil {
fmt.Println(err)
}
fmt.Println(provinceListJson)
var provinces []models.NmcProvince
json.Unmarshal([]byte(provinceListJson), &provinces)
//fmt.Println(provinces)
//fmt.Println(len(provinces))
for _, item := range provinces {
if models.GetNmcProvince(&item) {
//存在
fmt.Println("存在")
} else {
//不存在
models.NmcProvinceAdd(&item)
fmt.Println("不存在,插入数据库")
//http://www.nmc.cn/rest/province/ASX?_=1741055184606
//“http://www.nmc.cn/rest/province/" + code + "?_=" + String.valueOf(System.currentTimeMillis());
}
}
}

Binary file not shown.
Loading…
Cancel
Save