Added different formatting for telegram bot
This commit is contained in:
parent
35f8fa5a57
commit
89623f5f6a
18 changed files with 233 additions and 173 deletions
|
|
@ -11,7 +11,7 @@ import (
|
|||
const scgDomain = "https://starcitygames.com"
|
||||
const scgSearchUrlTemplate = "https://starcitygames.hawksearch.com/sites/starcitygames/?search_query="
|
||||
|
||||
func (f *Fetcher) getPrices(name string) ([]scgCardPrice, error) {
|
||||
func (f *Fetcher) GetPrices(name string) ([]ScgCardPrice, error) {
|
||||
prices, err := getPricesScg(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -22,7 +22,7 @@ func (f *Fetcher) getPrices(name string) ([]scgCardPrice, error) {
|
|||
return prices, nil
|
||||
}
|
||||
|
||||
func getPricesScg(name string) ([]scgCardPrice, error) {
|
||||
func getPricesScg(name string) ([]ScgCardPrice, error) {
|
||||
escapedName := url.QueryEscape(name)
|
||||
searchUrl := scgSearchUrlTemplate + escapedName
|
||||
node, err := htmlquery.LoadURL(searchUrl)
|
||||
|
|
@ -30,18 +30,18 @@ func getPricesScg(name string) ([]scgCardPrice, error) {
|
|||
return nil, errors.Wrap(err, "cannot load url")
|
||||
}
|
||||
blocks := htmlquery.Find(node, "//div[@class=\"hawk-results-item\"]")
|
||||
var results []scgCardPrice
|
||||
var results []ScgCardPrice
|
||||
for _, block := range blocks {
|
||||
price := scgCardPrice{}
|
||||
price := ScgCardPrice{}
|
||||
linkNode := htmlquery.FindOne(block, "//h2/a")
|
||||
price.link = scgDomain + htmlquery.SelectAttr(linkNode, "href")
|
||||
price.Link = scgDomain + htmlquery.SelectAttr(linkNode, "href")
|
||||
editionNode := htmlquery.FindOne(block, "//p[@class=\"hawk-results-item__category\"]/a")
|
||||
if !strings.HasPrefix(htmlquery.SelectAttr(editionNode, "href"), "/shop/singles/") {
|
||||
continue
|
||||
}
|
||||
price.edition = editionNode.FirstChild.Data
|
||||
price.Edition = editionNode.FirstChild.Data
|
||||
priceNode := htmlquery.FindOne(block, "//span[@class='hawk-old-price']|//div[contains(concat(' ',normalize-space(@class),' '),' hawk-results-item__options-table-cell--price ')]")
|
||||
price.price = priceNode.FirstChild.Data
|
||||
price.Price = priceNode.FirstChild.Data
|
||||
results = append(results, price)
|
||||
}
|
||||
return results, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue