@@ 31,7 31,7 @@ type theFeed struct {
func main() {
// get config parameters
- interval, server, clientId, clientSecret, username, password, feedURL := readConfig()
+ interval, ignore, server, clientId, clientSecret, username, password, feedURL := readConfig()
// daemonize
cntxt := &daemon.Context{
@@ 69,20 69,44 @@ func main() {
// run every x times and blocks the program to keep it running
cron := gocron.NewScheduler(time.UTC)
- cron.Every(interval).Minutes().Do(mastodonTask, c, feedURL)
+ cron.Every(interval).Minutes().Do(mastodonTask, c, feedURL, ignore)
cron.StartBlocking()
}
-func mastodonTask(c *mastodon.Client, feedURL string) {
+func mastodonTask(c *mastodon.Client, feedURL string, ignore []string) {
// here we do the heavy orchestration of the app
// gets feeds
feeds := parseFeed(feedURL)
// selects a ramdon item from the feed
- rand.Seed(time.Now().UnixNano())
- randToot := feeds[rand.Intn(len(feeds))]
-
+ //rand.Seed(time.Now().UnixNano())
+ //randToot := feeds[rand.Intn(len(feeds))]
+ var randToot theFeed
+ var check int
+
+ // check if item contains ignore words
+
+ for len(randToot.Title) <= 0 {
+ rand.Seed(time.Now().UnixNano())
+ randToot = feeds[rand.Intn(len(feeds))]
+
+ for check <= len(ignore) {
+ for _, word := range ignore {
+ if strings.Contains(randToot.Title, word) {
+ check = len(ignore)
+ randToot = theFeed{}
+ break
+
+ } else {
+ check++
+
+ }
+ }
+ randToot = theFeed{}
+ log.Println("salio del for loop en range")
+ }
+ }
// creates the formating of the toot
theToot := createTheToot(randToot)
@@ 152,7 176,7 @@ func parseCredentials(command string) (string, error) {
return sec, nil
}
-func readConfig() (int, string, string, string, string, string, string) {
+func readConfig() (int, []string, string, string, string, string, string, string) {
// read config.ini
// get all parameters
@@ 164,6 188,7 @@ func readConfig() (int, string, string, string, string, string, string) {
}
interval := cfg.Section("general").Key("interval").MustInt()
+ ignore := cfg.Section("general").Key("ignore").Strings(",")
server := cfg.Section("mastodon").Key("server").String()
clientId, err := parseCredentials(cfg.Section("mastodon").Key("client_id").String())
clientSecret, err := parseCredentials(cfg.Section("mastodon").Key("client_secret").String())
@@ 174,5 199,5 @@ func readConfig() (int, string, string, string, string, string, string) {
log.Fatal(err)
}
- return interval, server, clientId, clientSecret, username, password, feedURL
+ return interval, ignore, server, clientId, clientSecret, username, password, feedURL
}