Last active
December 28, 2018 02:53
-
-
Save ken39arg/1910ce953461feee289597f13c34efad to your computer and use it in GitHub Desktop.
apple store tier 価格出すやつ
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 ( | |
| "encoding/json" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "os" | |
| "strings" | |
| "github.com/olekukonko/tablewriter" | |
| ) | |
| const ( | |
| apiURL = "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/pricing/matrix" | |
| ) | |
| func main() { | |
| countries := flag.String("contries", "JP,US", "coutrie codes separate by `,`") | |
| flag.Parse() | |
| if err := run(strings.Split(*countries, ",")); err != nil { | |
| log.Fatal(err) | |
| } | |
| } | |
| type Res struct { | |
| Data Data `json:"data"` | |
| Messages map[string]interface{} `json:"messages"` | |
| StatusCode string `json:"statusCode"` | |
| } | |
| type Data struct { | |
| PricingTiers []Tier `json:"pricingTiers"` | |
| CountryCurrencyMap map[string]string `json:"countryCurrencyMap"` | |
| } | |
| type Tier struct { | |
| TierStem string `json:"tierStem"` | |
| TierName string `json:"tierName"` | |
| PricingInfo []PricingInfo `json:"pricingInfo"` | |
| } | |
| type PricingInfo struct { | |
| CountryCode string `json:"countryCode"` | |
| CurrencyCode string `json:"currencyCode"` | |
| WholesalePrice float64 `json:"wholesalePrice"` | |
| WholesalePrice2 float64 `json:"wholesalePrice2"` | |
| RetailPrice float64 `json:"retailPrice"` | |
| CurrencySymbol string `json:"currencySymbol"` | |
| } | |
| func run(countries []string) error { | |
| res, err := http.Get(apiURL) | |
| if err != nil { | |
| return err | |
| } | |
| defer res.Body.Close() | |
| var r Res | |
| if err = json.NewDecoder(res.Body).Decode(&r); err != nil { | |
| return err | |
| } | |
| if r.StatusCode != "SUCCESS" { | |
| return fmt.Errorf("statusCode is not success %#v", r) | |
| } | |
| table := tablewriter.NewWriter(os.Stdout) | |
| table.SetHeader(append([]string{"Tier Name"}, countries...)) | |
| for _, tier := range r.Data.PricingTiers { | |
| line := make([]string, 0, len(countries)+1) | |
| line = append(line, tier.TierName) | |
| for _, c := range countries { | |
| for _, p := range tier.PricingInfo { | |
| if p.CountryCode == c { | |
| line = append(line, fmt.Sprintf("%s%.3f (%s)", p.CurrencySymbol, p.RetailPrice, p.CurrencyCode)) | |
| break | |
| } | |
| } | |
| } | |
| table.Append(line) | |
| } | |
| table.Render() | |
| return nil | |
| } |
ken39arg
commented
Dec 28, 2018
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment