Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
30fbf1b611 | |||
70900ea2c7 | |||
322e908147 |
1
go.mod
1
go.mod
@ -10,6 +10,7 @@ require (
|
|||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/miekg/dns v1.1.26
|
github.com/miekg/dns v1.1.26
|
||||||
github.com/rs/cors v1.7.0
|
github.com/rs/cors v1.7.0
|
||||||
|
github.com/stoewer/go-strcase v1.2.0
|
||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
|
||||||
s32x.com/ovrstat v0.0.0-20200131231416-4cb42edd331d
|
s32x.com/ovrstat v0.0.0-20200131231416-4cb42edd331d
|
||||||
)
|
)
|
||||||
|
3
go.sum
3
go.sum
@ -63,10 +63,13 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
|||||||
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||||
github.com/seilem/ovrstat v0.0.0-20200123200456-7b7e24d39506 h1:xAdnQYUFimq8Uiz4Io7QlnNGV+4BtagWGC+DDxVG3Fo=
|
github.com/seilem/ovrstat v0.0.0-20200123200456-7b7e24d39506 h1:xAdnQYUFimq8Uiz4Io7QlnNGV+4BtagWGC+DDxVG3Fo=
|
||||||
github.com/seilem/ovrstat v0.0.0-20200123200456-7b7e24d39506/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
github.com/seilem/ovrstat v0.0.0-20200123200456-7b7e24d39506/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
||||||
|
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
|
||||||
|
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
|
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
|
||||||
|
39
main.go
39
main.go
@ -7,8 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"git.meow.tf/ow-api/ow-api/cache"
|
"git.meow.tf/ow-api/ow-api/cache"
|
||||||
"git.meow.tf/ow-api/ow-api/json-patch"
|
"git.meow.tf/ow-api/ow-api/json-patch"
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
|
"github.com/stoewer/go-strcase"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -19,7 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "2.3.7"
|
Version = "2.4.0"
|
||||||
|
|
||||||
OpAdd = "add"
|
OpAdd = "add"
|
||||||
OpRemove = "remove"
|
OpRemove = "remove"
|
||||||
@ -30,6 +32,7 @@ type ApiVersion int
|
|||||||
const (
|
const (
|
||||||
VersionOne ApiVersion = iota
|
VersionOne ApiVersion = iota
|
||||||
VersionTwo
|
VersionTwo
|
||||||
|
VersionThree
|
||||||
)
|
)
|
||||||
|
|
||||||
type gamesStats struct {
|
type gamesStats struct {
|
||||||
@ -124,34 +127,46 @@ func registerVersionTwo(router *httprouter.Router) {
|
|||||||
router.GET("/v2/stats/"+platform+"/:tag/heroes/:heroes", injectPlatform(platform, heroes))
|
router.GET("/v2/stats/"+platform+"/:tag/heroes/:heroes", injectPlatform(platform, heroes))
|
||||||
router.GET("/v2/stats/"+platform+"/:tag/profile", injectPlatform(platform, profile))
|
router.GET("/v2/stats/"+platform+"/:tag/profile", injectPlatform(platform, profile))
|
||||||
router.GET("/v2/stats/"+platform+"/:tag/complete", injectPlatform(platform, stats))
|
router.GET("/v2/stats/"+platform+"/:tag/complete", injectPlatform(platform, stats))
|
||||||
|
router.GET("/v3/stats/"+platform+"/:tag/heroes/:heroes", injectPlatform(platform, heroes))
|
||||||
|
router.GET("/v3/stats/"+platform+"/:tag/profile", injectPlatform(platform, profile))
|
||||||
|
router.GET("/v3/stats/"+platform+"/:tag/complete", injectPlatform(platform, stats))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version
|
// Version
|
||||||
router.GET("/v2/version", versionHandler)
|
router.GET("/v2/version", versionHandler)
|
||||||
|
router.GET("/v3/version", versionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadHeroNames() {
|
func loadHeroNames() {
|
||||||
stats, err := ovrstat.PCStats("cats-11481")
|
res, err := http.Get("https://playoverwatch.com/en-us/heroes/")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m := make(map[string]bool)
|
defer res.Body.Close()
|
||||||
|
|
||||||
for k := range stats.QuickPlayStats.TopHeroes {
|
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||||
m[k] = true
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for k := range stats.QuickPlayStats.CareerStats {
|
links := doc.Find(".hero-portrait-detailed")
|
||||||
m[k] = true
|
|
||||||
}
|
|
||||||
|
|
||||||
heroNames = make([]string, 0)
|
heroNames = make([]string, 0)
|
||||||
|
|
||||||
for k := range m {
|
links.Each(func(_ int, s *goquery.Selection) {
|
||||||
heroNames = append(heroNames, k)
|
val, exists := s.Attr("data-hero-id")
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heroNames = append(heroNames, strcase.LowerCamelCase(val))
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Println("Loaded heroes", heroNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -296,13 +311,13 @@ func statsResponse(w http.ResponseWriter, r *http.Request, ps httprouter.Params,
|
|||||||
iconUrl = rating.RankIcon
|
iconUrl = rating.RankIcon
|
||||||
}
|
}
|
||||||
|
|
||||||
rating = int(totalRating / len(stats.Ratings))
|
rating = totalRating / len(stats.Ratings)
|
||||||
|
|
||||||
urlBase := iconUrl[0 : strings.Index(iconUrl, "rank-icons/")+11]
|
urlBase := iconUrl[0 : strings.Index(iconUrl, "rank-icons/")+11]
|
||||||
|
|
||||||
ratingIcon = urlBase + iconFor(rating)
|
ratingIcon = urlBase + iconFor(rating)
|
||||||
|
|
||||||
if version == VersionTwo {
|
if version == VersionThree {
|
||||||
m := make(map[string]ovrstat.Rating)
|
m := make(map[string]ovrstat.Rating)
|
||||||
|
|
||||||
ratingsPatches := make([]patchOperation, len(stats.Ratings))
|
ratingsPatches := make([]patchOperation, len(stats.Ratings))
|
||||||
|
Reference in New Issue
Block a user