Compare commits

..

No commits in common. "develop" and "v0.2.1" have entirely different histories.

4 changed files with 28 additions and 6 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "sn-rss-to-tg",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "."
}
]
}

12
main.go
View File

@ -12,6 +12,18 @@ func WaitUntilNextUpdate() {
time.Sleep(dur)
}
func contains(rss *Rss, a Item) bool {
if rss == nil {
return false
}
for _, x := range rss.Channel.Items {
if x.Title == a.Title {
return true
}
}
return false
}
func main() {
defer db.Close()
for {

5
rss.go
View File

@ -14,7 +14,6 @@ type Item struct {
Link string `xml:"link"`
Description string `xml:"description"`
PubDate RssDate `xml:"pubDate"`
Author Author `xml:"author"`
}
type Channel struct {
@ -33,10 +32,6 @@ type RssDate struct {
time.Time
}
type Author struct {
Name string `xml:"name"`
}
func (c *RssDate) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v string
dateFormat := "Mon, 02 Jan 2006 15:04:05 GMT"

2
tg.go
View File

@ -33,7 +33,7 @@ func init() {
}
func SendItemToTelegram(item *Item) error {
text := fmt.Sprintf("%s\n_%s by_ [%s](https://stacker.news/%s)\n", item.Title, humanize.Time(item.PubDate.Time), item.Author.Name, item.Author.Name)
text := fmt.Sprintf("%s (%s)\n", item.Title, humanize.Time(item.PubDate.Time))
linkItem := item.Link != item.Guid
if linkItem {
text += fmt.Sprintf("[Link](%s) ", item.Link)