Archived
1
0
Fork 0
This repository has been archived on 2024-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
restockbot/utils.go
Julien Riou 5ac5f78ae2
Add Amazon support (#3)
This commit introduces the Amazon support with calls to the Product Advertising
API (PA API). For now, I was only able to use the "www.amazon.fr" marketplace.
I will add more marketplaces when my Amazon Associate accounts will be
validated.

Signed-off-by: Julien Riou <julien@riou.xyz>
2021-04-01 12:59:16 +02:00

28 lines
689 B
Go

package main
import (
"net/url"
"regexp"
"strings"
)
// ExtractShopName parses a link to extract the hostname, then remove leading www, to build the Shop name
// "https://www.ldlc.com/informatique/pieces-informatique/[...]" -> "ldlc.com"
func ExtractShopName(link string) (name string, err error) {
u, err := url.Parse(link)
if err != nil {
return "", err
}
re := regexp.MustCompile(`^www\.`)
return strings.ToLower(re.ReplaceAllString(u.Hostname(), "")), nil
}
// ContainsString returns true when string is found in the array of strings
func ContainsString(arr []string, str string) bool {
for _, elem := range arr {
if elem == str {
return true
}
}
return false
}