Skip to content

Instantly share code, notes, and snippets.

@taraspos
Last active April 15, 2024 10:24
Show Gist options
  • Save taraspos/e32f2dae099316f9ac74c42ffa72574e to your computer and use it in GitHub Desktop.
Save taraspos/e32f2dae099316f9ac74c42ffa72574e to your computer and use it in GitHub Desktop.
Filter Qwertees by hoodie availability

www.qwertee.com filtering script

I was trying to find hoodie for a present, however, QWERTEE website has very limited hoodies availability and no way to filter out on the website.

The only way to see if this specific design had a hoodie available is to open each end every, and only 10% of designs has it. So I ended up writting this very small script.

Object types are generated with:

Currently, pulloverhoodie is hardcoded in there, so feel free to change it for the type you need.

How to run?

package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
type Tee struct {
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
User struct {
ID int `json:"id"`
Username string `json:"username"`
} `json:"user"`
Zoom struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"zoom"`
Price struct {
Eur string `json:"EUR"`
Usd string `json:"USD"`
Gbp string `json:"GBP"`
} `json:"price"`
}
type TeeDetails struct {
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
User struct {
ID int `json:"id"`
Username string `json:"username"`
Blurb string `json:"blurb"`
} `json:"user"`
Zoom struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"zoom"`
Daily bool `json:"daily"`
StockLocation int `json:"stockLocation"`
PrintLocation int `json:"printLocation"`
Types []struct {
Name string `json:"name"`
Img struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"img"`
Price struct {
Eur string `json:"EUR"`
Usd string `json:"USD"`
Gbp string `json:"GBP"`
} `json:"price"`
Variations []struct {
Size string `json:"size"`
Stock int `json:"stock"`
Sku string `json:"sku"`
SizeFull string `json:"sizeFull"`
ColourHuman string `json:"colourHuman"`
Height any `json:"height"`
Width any `json:"width"`
} `json:"variations"`
} `json:"types"`
Social struct {
Facebook string `json:"facebook"`
Twitter string `json:"twitter"`
Email string `json:"email"`
} `json:"social"`
Popular []struct {
ID int `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
User struct {
ID int `json:"id"`
Username string `json:"username"`
} `json:"user"`
Zoom struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"zoom"`
Price struct {
Eur string `json:"EUR"`
Usd string `json:"USD"`
Gbp string `json:"GBP"`
} `json:"price"`
} `json:"popular"`
}
func main() {
resp, err := http.Get("https://site.qwertee.com/api/shop/tees")
if err != nil {
log.Panic(err)
}
defer resp.Body.Close()
var tees []Tee
if err := json.NewDecoder(resp.Body).Decode(&tees); err != nil {
log.Panic(err)
}
hoodiesBySize := map[string][]string{}
for i, t := range tees {
fmt.Println(i, "checking ", t.Slug)
rr, err := http.Get("https://site.qwertee.com/api/tee/" + t.Slug)
if err != nil {
log.Panic(err)
}
defer rr.Body.Close()
var teeDetails TeeDetails
if err := json.NewDecoder(rr.Body).Decode(&teeDetails); err != nil {
log.Panic(err)
}
for _, tt := range teeDetails.Types {
if tt.Name == "pulloverhoodie" {
for _, tv := range tt.Variations {
hoodiesBySize[tv.Size] = append(hoodiesBySize[tv.Size], t.Slug)
}
}
}
}
for s, hs := range hoodiesBySize {
// if !(s == "PHM" || s == "PHL") {
// continue
// }
fmt.Printf("Hoodies with %s size\n", s)
for i, h := range hs {
fmt.Printf("%d - %s - [https://www.qwertee.com/shop/tees/%s]\n", i, h, h)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment