-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (62 loc) · 1.63 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/xml"
"fmt"
"io"
"net/http"
"os"
)
type RSS struct {
XMLName xml.Name `xml:"rss"`
Channel *Channel `xml:"channel"`
}
type Channel struct {
Title string `xml:"title"`
ItemList []Item `xml:"item"`
}
type Item struct {
Title string `xml:"title"`
Link string `xml:"link"`
Traffic string `xml:"approx_traffic"`
NewsItems []News `xml:"news_item"`
}
type News struct {
Headline string `xml:"news_item_title"`
HeadlineLink string `xml:"news_item_url"`
}
func main() {
var r RSS
data := readGoogleTrends()
err := xml.Unmarshal(data, &r)
if err != nil {
fmt.Println("Error, err")
}
fmt.Println("\n Vous trouverez ci-dessous toutes les tendances de recherche Google en France pour aujourd'hui !")
fmt.Println("----------------------------------------------------------------")
for i := range r.Channel.ItemList {
rank := (i + 1)
fmt.Println("#", rank)
fmt.Println("Search term:", r.Channel.ItemList[i].Title)
fmt.Println("Link: ", r.Channel.ItemList[i].Link)
fmt.Println("Headline: ", r.Channel.ItemList[i].NewsItems[0].Headline)
fmt.Println("Link to article: ", r.Channel.ItemList[i].NewsItems[0].HeadlineLink)
fmt.Println("----------------------------------------------------------------")
}
}
func getGoogleTrends() *http.Response {
resp, err := http.Get("https://trends.google.com/trends/trendingsearches/daily/rss?geo=FR")
if err != nil {
fmt.Println("Error", err)
os.Exit(1)
}
return resp
}
func readGoogleTrends() []byte {
resp := getGoogleTrends()
data, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error", err)
os.Exit(1)
}
return data
}