-
Notifications
You must be signed in to change notification settings - Fork 0
/
rssreader.go
49 lines (41 loc) · 1.43 KB
/
rssreader.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
// +build windows
package main
import (
"fmt"
"time"
ole "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/go-ole/go-ole/oleutil"
)
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("Microsoft.XMLHTTP")
xmlhttp, _ := unknown.QueryInterface(ole.IID_IDispatch)
_, err := oleutil.CallMethod(xmlhttp, "open", "GET", "http://rss.slashdot.org/Slashdot/slashdot", false)
if err != nil {
panic(err.Error())
}
_, err = oleutil.CallMethod(xmlhttp, "send", nil)
if err != nil {
panic(err.Error())
}
state := -1
for state != 4 {
state = int(oleutil.MustGetProperty(xmlhttp, "readyState").Val)
time.Sleep(10000000)
}
responseXml := oleutil.MustGetProperty(xmlhttp, "responseXml").ToIDispatch()
items := oleutil.MustCallMethod(responseXml, "selectNodes", "/rss/channel/item").ToIDispatch()
length := int(oleutil.MustGetProperty(items, "length").Val)
for n := 0; n < length; n++ {
item := oleutil.MustGetProperty(items, "item", n).ToIDispatch()
title := oleutil.MustCallMethod(item, "selectSingleNode", "title").ToIDispatch()
fmt.Println(oleutil.MustGetProperty(title, "text").ToString())
link := oleutil.MustCallMethod(item, "selectSingleNode", "link").ToIDispatch()
fmt.Println(" " + oleutil.MustGetProperty(link, "text").ToString())
title.Release()
link.Release()
item.Release()
}
items.Release()
xmlhttp.Release()
}