Created
August 27, 2015 03:47
-
-
Save hirokazumiyaji/a58848049a074d291229 to your computer and use it in GitHub Desktop.
Google Play Application Version Checker
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 ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"regexp" | |
"strings" | |
) | |
const GooglePlayApplicationURLPrefix = "https://play.google.com/store/apps/details" | |
var ( | |
id = flag.String("id", "", "google play application id") | |
regex = regexp.MustCompile(`<div class="content" itemprop="softwareVersion">(.*?)</div>`) | |
) | |
func main() { | |
flag.Parse() | |
url := fmt.Sprintf("%s?id=%s", GooglePlayApplicationURLPrefix, *id) | |
res, err := http.Get(url) | |
if err ! = nil { | |
fmt.Printf("Request error: %v", err) | |
return | |
} | |
defer res.Body.Close() | |
body, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
fmt.Printf("Response Body read error: %v", err) | |
return | |
} | |
version := strings.Trim(regex.FindStringSubmatch(string(body))[1]) | |
fmt.Println("Current Version: %s", version) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment