Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Created August 27, 2015 03:47
Show Gist options
  • Save hirokazumiyaji/a58848049a074d291229 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/a58848049a074d291229 to your computer and use it in GitHub Desktop.
Google Play Application Version Checker
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