Skip to content

Instantly share code, notes, and snippets.

@wbyoko
Created November 1, 2013 20:32
Show Gist options
  • Select an option

  • Save wbyoko/7271513 to your computer and use it in GitHub Desktop.

Select an option

Save wbyoko/7271513 to your computer and use it in GitHub Desktop.
Watches url for text - used for nexus 5 updates
package main
import "fmt"
import "strings"
import "net/http"
import "bytes"
func pageContains(url string, checkFor string) bool {
resp, err := http.Get(url)
if err != nil {
return false
}
defer resp.Body.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
s := buf.String()
if strings.Contains(s, checkFor) {
return true
}
return false
}
func main() {
checkFor := "Add to cart"
urls := [...]string{"https://play.google.com/store/devices/details?id=nexus_5_black_16gb", "https://play.google.com/store/devices/details?id=nexus_5_white_16gb"}
color := "Black"
for index, url := range urls {
if index != 0 {
color = "White"
}
fmt.Printf("Checking for color %s", color)
fmt.Println("")
if pageContains(url, checkFor) {
fmt.Printf("Nexus 5 16 GB is available in %s", color)
fmt.Println("")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment