|
@@ -11,20 +11,20 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- sysconfig map[string]interface{} //配置文件
|
|
|
- save_mgo *MongodbSim //mongodb操作对象
|
|
|
- save_c_name string
|
|
|
+ sysconfig map[string]interface{} //配置文件
|
|
|
+ save_mgo *MongodbSim //mongodb操作对象
|
|
|
+ save_c_name string
|
|
|
)
|
|
|
-var Url = "https://www.jianyu360.com/article/content/%s.html"
|
|
|
+var Url = "https://www.jianyu360.cn/article/content/%s.html"
|
|
|
|
|
|
-func initMgo() {
|
|
|
+func initMgo() {
|
|
|
saveconf := sysconfig["save_mgodb"].(map[string]interface{})
|
|
|
save_c_name = qu.ObjToString(saveconf["coll"])
|
|
|
save_mgo = &MongodbSim{
|
|
|
MongodbAddr: saveconf["addr"].(string),
|
|
|
DbName: saveconf["db"].(string),
|
|
|
Size: qu.IntAllDef(saveconf["pool"], 5),
|
|
|
- Password: "zk@123123",
|
|
|
+ Password: "zk@123123",
|
|
|
UserName: "zhengkun",
|
|
|
}
|
|
|
save_mgo.InitPool()
|
|
@@ -36,11 +36,11 @@ func init() {
|
|
|
initMgo()
|
|
|
}
|
|
|
|
|
|
-func main() {
|
|
|
+func main() {
|
|
|
//定时任务
|
|
|
c := cron.New()
|
|
|
c.AddFunc("0 30 7 ? * *", func() {
|
|
|
- exportSpecSiteDataWeek() //周邮件-每周1点 8点
|
|
|
+ exportSpecSiteDataWeek() //周邮件-每周1点 8点
|
|
|
exportSpecSiteDataMonth() //月邮件-每月1号 8点
|
|
|
})
|
|
|
c.Start()
|
|
@@ -49,86 +49,84 @@ func main() {
|
|
|
exportSpecSiteDataWeek()
|
|
|
exportSpecSiteDataMonth()
|
|
|
|
|
|
-
|
|
|
- time.Sleep(99999*time.Hour)
|
|
|
+ time.Sleep(99999 * time.Hour)
|
|
|
}
|
|
|
|
|
|
//处理数据-周邮件
|
|
|
func exportSpecSiteDataWeek() {
|
|
|
cur_time := time.Now().Unix()
|
|
|
today := GetOneWeekDay(TimeStampToString(cur_time))
|
|
|
- if today!=1 {
|
|
|
+ if today != 1 {
|
|
|
return
|
|
|
}
|
|
|
log.Println("每周一:准备邮件数据...")
|
|
|
- now:=time.Now()
|
|
|
- durdays:=7*2
|
|
|
- start:= time.Date(now.Year(), now.Month(), now.Day()-durdays, 0, 0, 0, 0, time.Local).Unix()
|
|
|
+ now := time.Now()
|
|
|
+ durdays := 7 * 2
|
|
|
+ start := time.Date(now.Year(), now.Month(), now.Day()-durdays, 0, 0, 0, 0, time.Local).Unix()
|
|
|
end := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
|
|
|
|
|
|
- log.Println(start,end)
|
|
|
+ log.Println(start, end)
|
|
|
q := map[string]interface{}{
|
|
|
"comeintime": map[string]interface{}{
|
|
|
- "$gte": start,
|
|
|
- "$lt": end,
|
|
|
+ "$gte": start,
|
|
|
+ "$lt": end,
|
|
|
},
|
|
|
}
|
|
|
sess := save_mgo.GetMgoConn()
|
|
|
defer save_mgo.DestoryMongoConn(sess)
|
|
|
- log.Println("bidding 查询条件:",q)
|
|
|
+ log.Println("bidding 查询条件:", q)
|
|
|
//省份、公告标题、公告类别、发布时间、公告地址、项目名称、来源网站
|
|
|
it_site := sess.DB(save_mgo.DbName).C(save_c_name).Find(&q).Sort("comeintime").Select(map[string]interface{}{
|
|
|
- "area":1,
|
|
|
- "title":1,
|
|
|
- "subtype":1,
|
|
|
- "publishtime":1,
|
|
|
- "href":1,
|
|
|
- "projectname":1,
|
|
|
- "site":1,
|
|
|
+ "area": 1,
|
|
|
+ "title": 1,
|
|
|
+ "subtype": 1,
|
|
|
+ "publishtime": 1,
|
|
|
+ "href": 1,
|
|
|
+ "projectname": 1,
|
|
|
+ "site": 1,
|
|
|
}).Iter()
|
|
|
timeLayout := "2006-01-02"
|
|
|
- total,isok,dataArr:= 0,0,make([]map[string]string,0)
|
|
|
+ total, isok, dataArr := 0, 0, make([]map[string]string, 0)
|
|
|
for tmp := make(map[string]interface{}); it_site.Next(&tmp); total++ {
|
|
|
if total%10000 == 0 {
|
|
|
- log.Println("cur index :", total,isok)
|
|
|
+ log.Println("cur index :", total, isok)
|
|
|
}
|
|
|
- site:=qu.ObjToString(tmp["site"])
|
|
|
- area:=qu.ObjToString(tmp["area"])
|
|
|
- subtype:=qu.ObjToString(tmp["subtype"])
|
|
|
- projectname:=qu.ObjToString(tmp["projectname"])
|
|
|
- publishtime:=qu.Int64All(tmp["publishtime"])
|
|
|
- new_publishtime := ""//转日期
|
|
|
- if publishtime>0 {
|
|
|
+ site := qu.ObjToString(tmp["site"])
|
|
|
+ area := qu.ObjToString(tmp["area"])
|
|
|
+ subtype := qu.ObjToString(tmp["subtype"])
|
|
|
+ projectname := qu.ObjToString(tmp["projectname"])
|
|
|
+ publishtime := qu.Int64All(tmp["publishtime"])
|
|
|
+ new_publishtime := "" //转日期
|
|
|
+ if publishtime > 0 {
|
|
|
new_publishtime = time.Unix(publishtime, 0).Format(timeLayout)
|
|
|
}
|
|
|
- href:=qu.ObjToString(tmp["href"])
|
|
|
- title:=qu.ObjToString(tmp["title"])
|
|
|
+ href := qu.ObjToString(tmp["href"])
|
|
|
+ title := qu.ObjToString(tmp["title"])
|
|
|
|
|
|
- if (site=="上海政府采购网" || site=="中国政府采购网") && area=="上海" {
|
|
|
+ if (site == "上海政府采购网" || site == "中国政府采购网") && area == "上海" {
|
|
|
isok++
|
|
|
dataArr = append(dataArr, map[string]string{
|
|
|
- "area":area,
|
|
|
- "subtype":subtype,
|
|
|
- "title":title,
|
|
|
- "projectname":projectname,
|
|
|
- "site":site,
|
|
|
- "publishtime":new_publishtime,
|
|
|
- "href":href,
|
|
|
- "jyhref":fmt.Sprintf(Url, qu.CommonEncodeArticle("content", BsonTOStringId(tmp["_id"]))),
|
|
|
+ "area": area,
|
|
|
+ "subtype": subtype,
|
|
|
+ "title": title,
|
|
|
+ "projectname": projectname,
|
|
|
+ "site": site,
|
|
|
+ "publishtime": new_publishtime,
|
|
|
+ "href": href,
|
|
|
+ "jyhref": fmt.Sprintf(Url, qu.CommonEncodeArticle("content", BsonTOStringId(tmp["_id"]))),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
tmp = make(map[string]interface{})
|
|
|
}
|
|
|
- log.Println("is site over :",total,isok)
|
|
|
-
|
|
|
+ log.Println("is site over :", total, isok)
|
|
|
|
|
|
start_str := time.Unix(start, 0).Format(timeLayout)
|
|
|
end_str := time.Unix(end-1, 0).Format(timeLayout)
|
|
|
- xlsxName := "上海通服:"+start_str+"~"+end_str+".xlsx"
|
|
|
- log.Println("邮件名:",xlsxName)
|
|
|
+ xlsxName := "上海通服:" + start_str + "~" + end_str + ".xlsx"
|
|
|
+ log.Println("邮件名:", xlsxName)
|
|
|
os.Remove(xlsxName)
|
|
|
- f :=xlsx.NewFile()
|
|
|
+ f := xlsx.NewFile()
|
|
|
sheet, _ := f.AddSheet("上海数据")
|
|
|
row := sheet.AddRow()
|
|
|
//省份、公告标题、公告类别、发布时间、公告地址、项目名称、来源网站
|
|
@@ -141,7 +139,7 @@ func exportSpecSiteDataWeek() {
|
|
|
row.AddCell().Value = "公告地址"
|
|
|
row.AddCell().Value = "剑鱼地址"
|
|
|
|
|
|
- for _,tmp:=range dataArr {
|
|
|
+ for _, tmp := range dataArr {
|
|
|
row = sheet.AddRow()
|
|
|
row.AddCell().SetString(tmp["area"])
|
|
|
row.AddCell().SetString(tmp["subtype"])
|
|
@@ -156,11 +154,11 @@ func exportSpecSiteDataWeek() {
|
|
|
|
|
|
if err != nil {
|
|
|
log.Println("保存xlsx失败:", err)
|
|
|
- sendWarningSmtp("保存xlsx异常","请检查...上海通服...")
|
|
|
- }else {
|
|
|
+ sendWarningSmtp("保存xlsx异常", "请检查...上海通服...")
|
|
|
+ } else {
|
|
|
log.Println("保存xlsx成功:", err)
|
|
|
- body_str := fmt.Sprintf("日期:%s~%s\t\t总计:%d条",start_str,end_str,isok)
|
|
|
- sendErrMailSmtp("上海通服数据~周",body_str,xlsxName)
|
|
|
+ body_str := fmt.Sprintf("日期:%s~%s\t\t总计:%d条", start_str, end_str, isok)
|
|
|
+ sendErrMailSmtp("上海通服数据~周", body_str, xlsxName)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -168,79 +166,78 @@ func exportSpecSiteDataWeek() {
|
|
|
func exportSpecSiteDataMonth() {
|
|
|
cur_time := time.Now().Unix()
|
|
|
cur_day := time.Now().Day()
|
|
|
- if cur_day!=1 {
|
|
|
+ if cur_day != 1 {
|
|
|
return
|
|
|
}
|
|
|
today := GetOneWeekDay(TimeStampToString(cur_time))
|
|
|
log.Println("每月1号:准备邮件数据...")
|
|
|
- now:=time.Now()
|
|
|
- durdays:=int64(7)+today-int64(1)
|
|
|
- start:= time.Date(now.Year(), now.Month(), now.Day()-int(durdays), 0, 0, 0, 0, time.Local).Unix()
|
|
|
+ now := time.Now()
|
|
|
+ durdays := int64(7) + today - int64(1)
|
|
|
+ start := time.Date(now.Year(), now.Month(), now.Day()-int(durdays), 0, 0, 0, 0, time.Local).Unix()
|
|
|
end := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
|
|
|
|
|
|
- log.Println(start,end)
|
|
|
+ log.Println(start, end)
|
|
|
q := map[string]interface{}{
|
|
|
"comeintime": map[string]interface{}{
|
|
|
- "$gte": start,
|
|
|
- "$lt": end,
|
|
|
+ "$gte": start,
|
|
|
+ "$lt": end,
|
|
|
},
|
|
|
}
|
|
|
sess := save_mgo.GetMgoConn()
|
|
|
defer save_mgo.DestoryMongoConn(sess)
|
|
|
- log.Println("bidding 查询条件:",q)
|
|
|
+ log.Println("bidding 查询条件:", q)
|
|
|
//省份、公告标题、公告类别、发布时间、公告地址、项目名称、来源网站
|
|
|
it_site := sess.DB(save_mgo.DbName).C(save_c_name).Find(&q).Sort("comeintime").Select(map[string]interface{}{
|
|
|
- "area":1,
|
|
|
- "title":1,
|
|
|
- "subtype":1,
|
|
|
- "publishtime":1,
|
|
|
- "href":1,
|
|
|
- "projectname":1,
|
|
|
- "site":1,
|
|
|
+ "area": 1,
|
|
|
+ "title": 1,
|
|
|
+ "subtype": 1,
|
|
|
+ "publishtime": 1,
|
|
|
+ "href": 1,
|
|
|
+ "projectname": 1,
|
|
|
+ "site": 1,
|
|
|
}).Iter()
|
|
|
timeLayout := "2006-01-02"
|
|
|
- total,isok,dataArr:= 0,0,make([]map[string]string,0)
|
|
|
+ total, isok, dataArr := 0, 0, make([]map[string]string, 0)
|
|
|
for tmp := make(map[string]interface{}); it_site.Next(&tmp); total++ {
|
|
|
if total%10000 == 0 {
|
|
|
- log.Println("cur index :", total,isok)
|
|
|
+ log.Println("cur index :", total, isok)
|
|
|
}
|
|
|
- site:=qu.ObjToString(tmp["site"])
|
|
|
- area:=qu.ObjToString(tmp["area"])
|
|
|
- subtype:=qu.ObjToString(tmp["subtype"])
|
|
|
- projectname:=qu.ObjToString(tmp["projectname"])
|
|
|
- publishtime:=qu.Int64All(tmp["publishtime"])
|
|
|
- new_publishtime := ""//转日期
|
|
|
- if publishtime>0 {
|
|
|
+ site := qu.ObjToString(tmp["site"])
|
|
|
+ area := qu.ObjToString(tmp["area"])
|
|
|
+ subtype := qu.ObjToString(tmp["subtype"])
|
|
|
+ projectname := qu.ObjToString(tmp["projectname"])
|
|
|
+ publishtime := qu.Int64All(tmp["publishtime"])
|
|
|
+ new_publishtime := "" //转日期
|
|
|
+ if publishtime > 0 {
|
|
|
new_publishtime = time.Unix(publishtime, 0).Format(timeLayout)
|
|
|
}
|
|
|
- href:=qu.ObjToString(tmp["href"])
|
|
|
- title:=qu.ObjToString(tmp["title"])
|
|
|
+ href := qu.ObjToString(tmp["href"])
|
|
|
+ title := qu.ObjToString(tmp["title"])
|
|
|
|
|
|
- if (site=="上海政府采购网" || site=="中国政府采购网") && area=="上海" {
|
|
|
+ if (site == "上海政府采购网" || site == "中国政府采购网") && area == "上海" {
|
|
|
isok++
|
|
|
dataArr = append(dataArr, map[string]string{
|
|
|
- "area":area,
|
|
|
- "subtype":subtype,
|
|
|
- "title":title,
|
|
|
- "projectname":projectname,
|
|
|
- "site":site,
|
|
|
- "publishtime":new_publishtime,
|
|
|
- "href":href,
|
|
|
- "jyhref":fmt.Sprintf(Url, qu.CommonEncodeArticle("content", BsonTOStringId(tmp["_id"]))),
|
|
|
+ "area": area,
|
|
|
+ "subtype": subtype,
|
|
|
+ "title": title,
|
|
|
+ "projectname": projectname,
|
|
|
+ "site": site,
|
|
|
+ "publishtime": new_publishtime,
|
|
|
+ "href": href,
|
|
|
+ "jyhref": fmt.Sprintf(Url, qu.CommonEncodeArticle("content", BsonTOStringId(tmp["_id"]))),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
tmp = make(map[string]interface{})
|
|
|
}
|
|
|
- log.Println("is site over :",total,isok)
|
|
|
-
|
|
|
+ log.Println("is site over :", total, isok)
|
|
|
|
|
|
start_str := time.Unix(start, 0).Format(timeLayout)
|
|
|
end_str := time.Unix(end-1, 0).Format(timeLayout)
|
|
|
- xlsxName := "上海通服:"+start_str+"~"+end_str+".xlsx"
|
|
|
- log.Println("邮件名:",xlsxName)
|
|
|
+ xlsxName := "上海通服:" + start_str + "~" + end_str + ".xlsx"
|
|
|
+ log.Println("邮件名:", xlsxName)
|
|
|
os.Remove(xlsxName)
|
|
|
- f :=xlsx.NewFile()
|
|
|
+ f := xlsx.NewFile()
|
|
|
sheet, _ := f.AddSheet("上海数据")
|
|
|
row := sheet.AddRow()
|
|
|
//省份、公告标题、公告类别、发布时间、公告地址、项目名称、来源网站
|
|
@@ -253,7 +250,7 @@ func exportSpecSiteDataMonth() {
|
|
|
row.AddCell().Value = "公告地址"
|
|
|
row.AddCell().Value = "剑鱼地址"
|
|
|
|
|
|
- for _,tmp:=range dataArr {
|
|
|
+ for _, tmp := range dataArr {
|
|
|
row = sheet.AddRow()
|
|
|
row.AddCell().SetString(tmp["area"])
|
|
|
row.AddCell().SetString(tmp["subtype"])
|
|
@@ -267,10 +264,10 @@ func exportSpecSiteDataMonth() {
|
|
|
err := f.Save(xlsxName)
|
|
|
if err != nil {
|
|
|
log.Println("保存xlsx失败:", err)
|
|
|
- sendWarningSmtp("保存xlsx异常","请检查...上海通服...")
|
|
|
- }else {
|
|
|
+ sendWarningSmtp("保存xlsx异常", "请检查...上海通服...")
|
|
|
+ } else {
|
|
|
log.Println("保存xlsx成功:", err)
|
|
|
- body_str := fmt.Sprintf("日期:%s~%s\t\t总计:%d条",start_str,end_str,isok)
|
|
|
- sendErrMailSmtp("上海通服数据~月)",body_str,xlsxName)
|
|
|
+ body_str := fmt.Sprintf("日期:%s~%s\t\t总计:%d条", start_str, end_str, isok)
|
|
|
+ sendErrMailSmtp("上海通服数据~月)", body_str, xlsxName)
|
|
|
}
|
|
|
-}
|
|
|
+}
|