1
Fork 0

Add support for German notification text
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Jan-Lukas Else 2020-06-30 19:53:47 +02:00
parent d635cd43ff
commit 45fda33f8a
2 changed files with 16 additions and 7 deletions

View File

@ -1,9 +1,9 @@
FROM golang:1.14-alpine as build FROM golang:1.14-alpine3.12 as build
ADD . /app ADD . /app
WORKDIR /app WORKDIR /app
RUN go build RUN go build
FROM alpine:3.11 FROM alpine:3.12
RUN apk add --no-cache tzdata ca-certificates RUN apk add --no-cache tzdata ca-certificates
COPY --from=build /app/JsonFeedToTelegram /bin/ COPY --from=build /app/JsonFeedToTelegram /bin/
WORKDIR /app WORKDIR /app

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -16,6 +15,10 @@ func main() {
feed, feedSet := os.LookupEnv("FEED") feed, feedSet := os.LookupEnv("FEED")
botToken, botTokenSet := os.LookupEnv("BOT_TOKEN") botToken, botTokenSet := os.LookupEnv("BOT_TOKEN")
channel, channelSet := os.LookupEnv("CHANNEL") channel, channelSet := os.LookupEnv("CHANNEL")
language, languageSet := os.LookupEnv("LANGUAGE")
if !languageSet {
language = "en"
}
if lastArticleFileSet && feedSet && botTokenSet && channelSet { if lastArticleFileSet && feedSet && botTokenSet && channelSet {
telegram := Telegram{botToken: botToken, channel: channel} telegram := Telegram{botToken: botToken, channel: channel}
http.HandleFunc("/hook", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/hook", func(w http.ResponseWriter, r *http.Request) {
@ -30,7 +33,7 @@ func main() {
return return
} }
if lastArticle := lastArticleUrl(lastArticleFile); lastArticle != article.Url { if lastArticle := lastArticleUrl(lastArticleFile); lastArticle != article.Url {
err = telegram.Post(createMessage(article)) err = telegram.Post(createMessage(article, language))
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
@ -40,8 +43,10 @@ func main() {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
w.WriteHeader(http.StatusCreated)
return
} else { } else {
http.Error(w, errors.New("no new article").Error(), http.StatusInternalServerError) w.WriteHeader(http.StatusOK)
return return
} }
}) })
@ -60,9 +65,13 @@ func updateLastArticleUrl(filename, url string) error {
return ioutil.WriteFile(filename, []byte(url), 0644) return ioutil.WriteFile(filename, []byte(url), 0644)
} }
func createMessage(article *Article) string { func createMessage(article *Article, lang string) string {
var message bytes.Buffer var message bytes.Buffer
message.WriteString("🔔 Something new was published") if lang == "de" {
message.WriteString("🔔 Etwas neues wurde veröffentlicht")
} else {
message.WriteString("🔔 Something new was published")
}
message.WriteString("\n\n") message.WriteString("\n\n")
if article.Title != "" { if article.Title != "" {
message.WriteString(article.Title) message.WriteString(article.Title)