This is a creation in Article, where the information may have evolved or changed.
When you visit a blog, you find someone raises a question, how to judge whether it is a holiday. Think for a while and think of two solutions
1. Keep track of your holiday information 2. Third-party Data interface
I recorded this directly by my pass off, cumbersome and may be lost and the like. Then the third-party data interface is the solution.
Through Baidu found a look good
https://www.juhe.cn/docs/api/id/177/aid/601
Request Parameter Description:
|
name |
required |
type |
description |
|
Key |
Is |
String |
Appkey you are applying for |
|
Year |
Is |
String |
Specify the year in YYYY format, for example: 2015 |
Return parameter Description:
|
name |
type |
description |
|
Error_code |
Int |
Return Status Code |
|
Reason |
String |
return reason |
|
Result |
String |
Return entity Content |
|
Holidaylist |
String |
Current year holiday list |
|
Year |
String |
Year |
Free 100 times, overall very good. After reviewing his parameters, I began to write the code formally.
First, I'm using the Beego HTTP library.
package mainimport ("github.com/astaxie/beego/httplib""strconv""log")var (//个人appKeyAppKey = "")func main() {//从1970年到2070年for i := 0; i <= 100; i++ {year := strconv.Itoa(1970 + i) //年份request := httplib.Get("http://v.juhe.cn/calendar/year?year=" + year + "&key=" + AppKey)//保存为文件if err := request.ToFile("data/" + year + ".json"); err != nil {log.Println(err.Error())}log.Println(year + " 成功")}}