Compare commits

...

4 Commits

Author SHA1 Message Date
ekzyis
4865e2e300 Remove .vscode 2024-04-29 02:04:15 +00:00
ekzyis
35c7baa854 Add author 2023-08-22 03:49:58 +02:00
ekzyis
0e1a3fe25d Remove unused code 2023-08-22 03:22:03 +02:00
ekzyis
2693ef2378 Check for new top posts every minute 2023-05-15 12:16:47 +02:00
4 changed files with 7 additions and 29 deletions

15
.vscode/launch.json vendored
View File

@ -1,15 +0,0 @@
{
// 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": "."
}
]
}

14
main.go
View File

@ -7,23 +7,11 @@ import (
func WaitUntilNextUpdate() {
now := time.Now()
dur := now.Truncate(time.Hour).Add(time.Hour).Sub(now)
dur := now.Truncate(time.Minute).Add(time.Minute).Sub(now)
log.Println("sleeping for", dur.Round(time.Second))
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,6 +14,7 @@ type Item struct {
Link string `xml:"link"`
Description string `xml:"description"`
PubDate RssDate `xml:"pubDate"`
Author Author `xml:"author"`
}
type Channel struct {
@ -32,6 +33,10 @@ 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 (%s)\n", item.Title, humanize.Time(item.PubDate.Time))
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)
linkItem := item.Link != item.Guid
if linkItem {
text += fmt.Sprintf("[Link](%s) ", item.Link)