Add Telegram Messenger notifications
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
e67ab63ca8
commit
0a9ae46d19
11 changed files with 255 additions and 39 deletions
19
notifier.go
19
notifier.go
|
|
@ -1,9 +1,26 @@
|
|||
package main
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Notifier interface to notify when a product becomes available or is sold out again
|
||||
type Notifier interface {
|
||||
NotifyWhenAvailable(string, string, float64, string, string) error
|
||||
NotifyWhenNotAvailable(string, time.Duration) error
|
||||
}
|
||||
|
||||
// formatPrice using internationalization rules
|
||||
// euro sign is placed after the value
|
||||
// default the currency, or symbol if applicable, is placed before the value
|
||||
func formatPrice(value float64, currency string) string {
|
||||
switch {
|
||||
case currency == "EUR":
|
||||
return fmt.Sprintf("%.2f€", value)
|
||||
case currency == "USD":
|
||||
return fmt.Sprintf("$%.2f", value)
|
||||
default:
|
||||
return fmt.Sprintf("%s%.2f", currency, value)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue