Skip to content

Instantly share code, notes, and snippets.

@TimothyYe
Created November 5, 2017 14:17
Show Gist options
  • Save TimothyYe/3442d92f12f691d61b19870a40d60b01 to your computer and use it in GitHub Desktop.
Save TimothyYe/3442d92f12f691d61b19870a40d60b01 to your computer and use it in GitHub Desktop.
Pumpcloud monitor program
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/parnurzeal/gorequest"
)
func main() {
var err error
doc, err := goquery.NewDocument("https://pumpcloud.net/clientarea/cart.php")
if err != nil {
log.Fatal(err)
os.Exit(1)
}
//Find 4.99 package
txt := strings.TrimSpace(doc.Find("#product1-unavailable").Text())
if txt != "Out of Stock" {
fmt.Println("not found")
sendNotify("stock")
} else {
fmt.Println(txt)
}
}
//X-LC-Id 为Leancloud API的KEY_ID
//X-LC-Key 为Leancloud API的KEY
//mobilePhoneNumber 为接受通知短信的手机号码
func sendNotify(template string) {
request := gorequest.New()
resp, body, _ := request.Post("https://r0hnoibm.api.lncld.net/1.1/requestSmsCode").
Set("X-LC-Id", "").
Set("X-LC-Key", "").
Set("Content-Type", "application/json").
Send(fmt.Sprintf(`{"mobilePhoneNumber": "13888888888", "template":"%s","sign":"XDC"}`, template)).
End()
if resp.StatusCode != 200 {
fmt.Println("err:", body)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment