博客园刷星golang v0.1
2015-09-16 10:29
393 查看
最近爽了把golang,写个刷星代码练练手。
程序入口:
检查最新的一条闪存状态:
插入一条新的闪存:
删除没有star的闪存:
就酱紫!以后心情好再改进。
程序入口:
func main() { for i := 1; i < 20; i++ { ing := getLastIng() if strings.Contains(ing, "幸运闪") { insertIng(i) } else { deleteIng(ing) } time.Sleep(15 * time.Minute) }}
检查最新的一条闪存状态:
func getLastIng() (text string) { client := &http.Client{} req, _ := http.NewRequest("GET", "http://ing.cnblogs.com/ajax/ing/GetIngList?IngListType=my&PageIndex=1&PageSize=1&Tag=&_=1441948524646", nil) req.Header.Set("Content-Type", "application/json; charset=UTF-8") req.Header.Set("Cookie", cookie) resp, err := client.Do(req) defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { // handle error } return string(body)}
插入一条新的闪存:
ing := Ing{} ing.PublicFlag = 1 rand.Seed(time.Now().Unix()) ing.Content = "mm" + strconv.Itoa(rand.Intn(100)) text, _ := json.Marshal(ing) client := &http.Client{} req, err := http.NewRequest("POST", "http://ing.cnblogs.com/ajax/ing/Publish", bytes.NewReader(text)) if err != nil { } req.Header.Set("Content-Type", "application/json; charset=UTF-8") req.Header.Set("Cookie", cookie) resp, err := client.Do(req) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body))
删除没有star的闪存:
func deleteIng(ing string) { begin := strings.Index(ing, "DelIng(") l := len("DelIng(") ingId := ing[begin+l : begin+l+6] fmt.Println("{ingId:" + ingId + "}") client := &http.Client{} req, _ := http.NewRequest("POST", "http://ing.cnblogs.com/ajax/ing/del", strings.NewReader("{ingId:"+ingId+"}")) req.Header.Set("Content-Type", "application/json; charset=UTF-8") req.Header.Set("Cookie", cookie) resp, err := client.Do(req) defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) } fmt.Println(string(body))}
就酱紫!以后心情好再改进。
相关文章推荐
- ubuntu14.04 安装google chrome
- Django框架如何使用ajax的post方法
- mac下安装go
- emoji 表情过滤 解决 sogo 输入法输入表情 服务器不支持
- google bigtable论文,其引用的文献都应该很经典
- Algorithms - Week 4-1 Elementary Symbol Tables
- Best Compression Algorithms(网易游戏2015笔试题)
- POJ1389Area of Simple Polygons【离散化+线段树+扫描线】
- django获取url参数总结
- UVALive 5985 Robbing Gringotts(费用流 + 折半状压)
- mongo分片
- 网易2016两道题Assuming Digits && Best Compression Algorithms
- GOF23设计模式之 建造者模式
- OC分类(Category)的作用和注意事项
- mongo第一天(mongo初体验)
- 在Mac OSX下安装和使用GO语言
- django 1.8 官方文档翻译:2-1-1 模型语法
- django 1.8 官方文档翻译:5-1-4 内建的Widget
- django 1.8 官方文档翻译:5-1-2 表单API
- pgpgin|pgpgout|pswpin|pswpout意义与差异