Archived
1
0
Fork 0

Release 0.2.0

- new language: go
- new shops: cybertek.fr, mediamarkt.ch
- deprecated shops: alternate.be, minershop.eu
- improved database transaction management
- better web parsing library (ferret, requires headless chrome browser)
- include or exclude products by applying regex on their names
- check for PID file to avoid running the bot twice
- hastags are now configurable

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-02-23 18:29:27 +01:00
commit 3a4aba93e5
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
26 changed files with 1354 additions and 1054 deletions

29
utils.go Normal file
View file

@ -0,0 +1,29 @@
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
}
// compileRegex transforms a regex from string to regexp instance
func compileRegex(pattern string) (regex *regexp.Regexp, err error) {
if pattern != "" {
regex, err = regexp.Compile(pattern)
if err != nil {
return nil, err
}
}
return regex, nil
}