-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
70 lines (46 loc) · 1.33 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
package main
import (
"fmt"
"os"
"time"
"github.com/hrittikhere/feedposter/extractor"
"github.com/hrittikhere/feedposter/platforms"
"github.com/mmcdole/gofeed"
)
func main() {
file, err := os.ReadFile("feed.yaml")
if err != nil {
fmt.Println("Error reading config file: ", err)
}
data := extractor.GetFeedURL(file)
for _, FeedURL := range data {
postParser(FeedURL)
}
}
func postParser(FeedURL string) {
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(FeedURL)
for _, item := range feed.Items {
NowTime := time.Now()
ParsedNowTime := time.Unix(NowTime.Unix(), 0)
PublishedTime := item.PublishedParsed
ParsedPublishedTime := time.Unix(PublishedTime.Unix(), 0)
if ParsedNowTime.Sub(ParsedPublishedTime).Hours() < 24 {
PostTitle := item.Title
PostLink := item.Link
PostAuthor := item.Author.Name
Category := item.Categories
hashtags, _ := getHastags(Category)
Tweet := fmt.Sprintf("%s was published by %s 🎉🎉🎉 \n %s \n %s", PostTitle, PostAuthor, hashtags, PostLink)
TweeetId, _ := platform.PublishToTwitter(Tweet)
fmt.Printf("%s with the TweetID: %s was posted! ✔️ \n ", PostTitle, TweeetId)
}
}
}
func getHastags(Categories []string) (string, error) {
var Category string
for _, element := range Categories {
Category += "#" + element + " "
}
return Category, nil
}