@@ -16,7 +16,7 @@ import (
1616const ApiUrl string = "https://www.tagesschau.de/json/headerapp"
1717
1818type TagesschauResponse struct {
19- BreakingNews struct {
19+ BreakingNews [] struct {
2020 Id string `json:"id"`
2121 Headline string `json:"headline"`
2222 Text string `json:"text"`
@@ -60,14 +60,16 @@ func (h Handler) check() error {
6060 return fmt .Errorf ("can not unmarshal JSON: %w" , err )
6161 }
6262
63- if result .BreakingNews .Id == "" {
63+ if len ( result .BreakingNews ) == 0 || result . BreakingNews [ 0 ] .Id == "" {
6464 if isDebugMode () {
6565 log .Println ("No breaking news found" )
6666 }
6767 return nil
6868 }
6969
70- if result .BreakingNews .Url == "" {
70+ breakingNews := result .BreakingNews [0 ]
71+
72+ if breakingNews .Url == "" {
7173 return errors .New ("invalid breaking news" )
7274 }
7375
@@ -76,7 +78,7 @@ func (h Handler) check() error {
7678 return fmt .Errorf ("error while getting last entry: %w" , err )
7779 }
7880
79- if lastEntry == result . BreakingNews .Id {
81+ if lastEntry == breakingNews .Id {
8082 if isDebugMode () {
8183 log .Println ("Already notified of this breaking news" )
8284 }
@@ -87,15 +89,20 @@ func (h Handler) check() error {
8789
8890 sb := strings.Builder {}
8991
90- sb .WriteString (fmt .Sprintf ("<b>%s</b>\n " , html .EscapeString (result .BreakingNews .Headline )))
91- sb .WriteString (fmt .Sprintf ("<i>%s</i>\n " , html .EscapeString (result .BreakingNews .Date )))
92- if result .BreakingNews .Text != "" {
93- sb .WriteString (fmt .Sprintf ("%s\n " , html .EscapeString (strings .TrimSpace (result .BreakingNews .Text ))))
92+ sb .WriteString (fmt .Sprintf ("<b>%s</b>\n " , html .EscapeString (breakingNews .Headline )))
93+ sb .WriteString (fmt .Sprintf ("<i>%s</i>\n " , html .EscapeString (strings .Replace (breakingNews .Date , "Stand: " , "" , 1 ))))
94+ if breakingNews .Text != "" {
95+ sb .WriteString (fmt .Sprintf ("%s\n " , html .EscapeString (strings .TrimSpace (breakingNews .Text ))))
96+ }
97+
98+ url := breakingNews .Url
99+ if ! strings .HasPrefix (url , "http" ) {
100+ url = "https://www.tagesschau.de/" + url
94101 }
95102
96- textLink := fmt .Sprintf ("<a href=\" %s\" >Eilmeldung aufrufen</a>" , result . BreakingNews . Url )
103+ textLink := fmt .Sprintf ("<a href=\" %s\" >Eilmeldung aufrufen</a>" , url )
97104 replyMarkup := h .Bot .NewMarkup ()
98- btn := replyMarkup .URL ("Eilmeldung aufrufen" , result . BreakingNews . Url )
105+ btn := replyMarkup .URL ("Eilmeldung aufrufen" , url )
99106 replyMarkup .Inline (replyMarkup .Row (btn ))
100107
101108 groupText := "#EIL: " + sb .String ()
@@ -122,7 +129,7 @@ func (h Handler) check() error {
122129 }
123130 }
124131
125- err = h .DB .System .SetLastEntry (result . BreakingNews .Id )
132+ err = h .DB .System .SetLastEntry (breakingNews .Id )
126133 if err != nil {
127134 return fmt .Errorf ("failed writing last entry to DB: %w" , err )
128135 }
0 commit comments