Item price support
This commit is contained in:
@@ -122,8 +122,13 @@ func findItemInfobox(templates []extract.Infobox) *extract.Infobox {
|
||||
}
|
||||
|
||||
func renderGEPrice(md *render.Builder, name, pageTitle string) {
|
||||
if Game() == "rs3" {
|
||||
renderRS3GEPrice(md, pageTitle)
|
||||
return
|
||||
}
|
||||
|
||||
priceClient := prices.NewClient(GamePriceBaseURL())
|
||||
mc := prices.NewMappingCache(priceClient)
|
||||
mc := prices.NewMappingCache(priceClient, Game())
|
||||
if err := mc.Load(); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -152,6 +157,32 @@ func renderGEPrice(md *render.Builder, name, pageTitle string) {
|
||||
md.Newline()
|
||||
}
|
||||
|
||||
func renderRS3GEPrice(md *render.Builder, pageTitle string) {
|
||||
wikiClient := wiki.NewClient(GameBaseURL())
|
||||
exchangeItem, err := wikiClient.GetExchangeModule(pageTitle)
|
||||
if err != nil || exchangeItem == nil {
|
||||
return
|
||||
}
|
||||
|
||||
rs3Client := prices.NewRS3Client()
|
||||
detail, err := rs3Client.GetDetail(exchangeItem.ItemID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
md.H2("Grand Exchange")
|
||||
md.KV("Current price", detail.CurrentPrice+" gp")
|
||||
if detail.TodayPrice != 0 {
|
||||
md.KV("Today's change", render.FormatGP(detail.TodayPrice))
|
||||
} else {
|
||||
md.KV("Today's change", "0 gp")
|
||||
}
|
||||
if exchangeItem.Limit > 0 {
|
||||
md.KV("Buy limit", render.FormatNumber(exchangeItem.Limit))
|
||||
}
|
||||
md.Newline()
|
||||
}
|
||||
|
||||
func renderDropSources(md *render.Builder, templates []extract.Infobox) {
|
||||
drops := extract.FindAllTemplates(templates, "DropsLine")
|
||||
if len(drops) == 0 {
|
||||
@@ -182,7 +213,7 @@ func renderSourcesSection(md *render.Builder, page *wiki.ParsedPage, client *wik
|
||||
lower := strings.ToLower(s.Line)
|
||||
if lower == "item sources" || lower == "sources" || lower == "obtaining" || lower == "acquisition" {
|
||||
idx := 0
|
||||
fmt.Sscanf(s.Index, "%d", &idx)
|
||||
_, _ = fmt.Sscanf(s.Index, "%d", &idx)
|
||||
if idx > 0 {
|
||||
sectionPage, err := client.GetPageSection(title, idx)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user