Created
November 1, 2013 20:32
-
-
Save wbyoko/7271513 to your computer and use it in GitHub Desktop.
Watches url for text - used for nexus 5 updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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