Skip to content

Commit f9ef7d0

Browse files
committed
First working draft
1 parent ddf01c2 commit f9ef7d0

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# PredB.me RSS feed Parser
22

3+
[![Build Status](https://travis-ci.org/luckylittle/predb_me_rss_parser.svg?branch=master)](https://travis-ci.org/luckylittle/predb_me_rss_parser)
4+
[![GitHub license](https://img.shields.io/github/license/luckylittle/predb_me_rss_parser.svg)](https://github.com/luckylittle/predb_me_rss_parser/blob/master/LICENSE)
5+
[![Version](https://img.shields.io/badge/Version-0.0.1-green.svg)](https://github.com/luckylittle/predb_me_rss_parser/releases)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/luckylittle/predb_me_rss_parser)](https://goreportcard.com/report/github.com/luckylittle/predb_me_rss_parser)
7+
8+
39
[Golang](https://golang.org/) implementation of the [RSS feed](https://en.wikipedia.org/wiki/RSS) parser explicitly for the [PreDB.me](https://predb.me/) website (uses minimal Atom 2.0 feed type without pub date).
410

511
## Technical details
612

713
1. HTTP GET https://predb.me/?rss=1
14+
![xml_document_tree.png](img/xml_document_tree.png)
815
2. Transform `<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> ... </rss>` into XML struct:
916
- 1x top item `<channel> ... </channel>` contains
1017
- 40x nested `<item> ... </item>` items which each contain
11-
- 1x `<title> ... </title>`
18+
- 1x `<title> ... </title>` for each item
1219
3. Create a list of the 40 titles, while caching the information of the latest title (first `<title>` is the latest)
1320
4. Run steps 1.-3. every `X` minutes
1421

@@ -18,4 +25,4 @@ As a backup, similar RSS feed https://predb.ovh/api/v1/rss can be used, or for s
1825

1926
---
2027

21-
_Last update: Thu Jan 9 00:22:18 UTC 2020_
28+
_Last update: Thu Jan 23 23:52:43 UTC 2020_

img/xml_document_tree.png

45 KB
Loading

main.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"encoding/xml"
5+
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"net/http"
9+
)
10+
11+
/*Rss structure contains one channel, which further contains fourty items each with one release title*/
12+
type Rss struct {
13+
XMLName xml.Name `xml:"rss"`
14+
Text string `xml:",chardata"`
15+
Version string `xml:"version,attr"`
16+
Atom string `xml:"atom,attr"`
17+
Channel struct {
18+
Text string `xml:",chardata"`
19+
Title string `xml:"title"`
20+
Link string `xml:"link"`
21+
Description string `xml:"description"`
22+
Item []struct {
23+
Text string `xml:",chardata"`
24+
Title string `xml:"title"`
25+
Link string `xml:"link"`
26+
} `xml:"item"`
27+
} `xml:"channel"`
28+
}
29+
30+
func main() {
31+
resp, err := http.Get("https://predb.me/?rss=1")
32+
if err != nil {
33+
log.Fatalln(err)
34+
}
35+
36+
defer resp.Body.Close()
37+
38+
body, err := ioutil.ReadAll(resp.Body)
39+
if err != nil {
40+
log.Fatalln(err)
41+
}
42+
43+
bs := []byte(body)
44+
45+
var releases Rss
46+
47+
xml.Unmarshal(bs, &releases)
48+
49+
for i := 0; i < len(releases.Channel.Item); i++ {
50+
fmt.Println(releases.Channel.Item[i].Title)
51+
}
52+
}

0 commit comments

Comments
 (0)