-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (62 loc) · 1.67 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
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"encoding/xml"
)
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 Below are all the Google Search Trens for Today!")
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 to the Trend:", r.Channel.ItemList[i].Link)
fmt.Println("News Headline:", r.Channel.ItemList[i].NewsItems[0].Headline)
fmt.Println("Linke to article:", r.Channel.ItemList[i].NewsItems[0].HeadlineLink)
fmt.Println("\n=======================================================================================================================================================\n")
}
}
func readGoogleTrends() []byte {
resp := getGoogleTrends()
data, err := ioutil.ReadAll(resp.Body)
if err != nil{
fmt.Println(err)
os.Exit(1)
}
return data
}
func getGoogleTrends() *http.Response {
resp, err := http.Get("https://trends.google.com/trends/trendingsearches/daily/rss?geo=US")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return resp
}