Skip to content

Commit

Permalink
Implement mute list
Browse files Browse the repository at this point in the history
  • Loading branch information
dtonon committed Dec 18, 2023
1 parent 5235a9e commit 08f31bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
10 changes: 7 additions & 3 deletions README.md
@@ -1,6 +1,6 @@
# Stacker Beep

Use this command line utility to be informed, with a *beep*, about new content of Stacker.news, filtering by authors, topics, domains and territory.
Use this command line utility to be informed, with a *beep*, about new content of Stacker.news, filtering by authors, topics, domains and territory. A mute list is also supported.

![](screen.png)

Expand All @@ -13,11 +13,15 @@ For `-nostr-from` use a random key, **not** your private key. A static key, vers
## Usage examples

```
sn-alert -authors=sn,k00b,kr,ekzyis,hn -topics=nostr,adoption,onboarding,wallet,hack -domains=github,lopp
stacker-beep -authors=sn,k00b,kr,ekzyis,hn \
-topics=nostr,adoption,onboarding,wallet,hack \
-domains=github,lopp
```

```
stacker-beep -topics=channel,fee,node -territory=bitcoin
stacker-beep -topics=channel,fee,node \
-mute=eth
-territory=bitcoin
```

```
Expand Down
47 changes: 16 additions & 31 deletions main.go
Expand Up @@ -32,6 +32,7 @@ var (
acceptAuthors []string
interestingTopics []string
interestingDomains []string
mutedWords []string
territory string
checkInterval time.Duration
targetURL string
Expand All @@ -54,6 +55,7 @@ func main() {
authorsPtr := flag.String("authors", "", "Comma-separated list of accepted authors")
topicsPtr := flag.String("topics", "", "Comma-separated list of interesting topics")
domainsPtr := flag.String("domains", "", "Comma-separated list of interesting domains")
mutedWordsPtr := flag.String("mute", "", "Comma-separated list of muted words (applied to authors, topics, domains)")
territoryPtr := flag.String("territory", "", "Territory, default is home (all)")
nostrNotifierPrivKeyPtr := flag.String("nostr-from", "", "Nostr private hex key of the notifier")
nostrRecipientPubKeyPtr := flag.String("nostr-to", "", "Nostr public hex key of the recipient (you!)")
Expand All @@ -77,6 +79,9 @@ func main() {
if *domainsPtr != "" {
interestingDomains = strings.Split(*domainsPtr, ",")
}
if *mutedWordsPtr != "" {
mutedWords = strings.Split(*mutedWordsPtr, ",")
}
if *territoryPtr != "" {
territory = *territoryPtr
}
Expand Down Expand Up @@ -148,9 +153,12 @@ func checkForNewItems(interval time.Duration) {
return
}
if time.Since(parsedDate) < interval &&
(isAuthorAccepted(author) ||
containsInterestingTopic(title) ||
containsInterestingDomains(domain)) {
(isIncluded(author, acceptAuthors, true) ||
isIncluded(title, interestingTopics, false) ||
isIncluded(domain, interestingDomains, false)) &&
!isIncluded(author, mutedWords, true) &&
!isIncluded(title, mutedWords, false) &&
!isIncluded(domain, mutedWords, false) {
localTime := parsedDate.Local().Format("2006-01-02 15:04")
fmt.Println(customMagenta + author + reset + " - " + customGray + localTime + reset)
fmt.Println(customBlu + title + reset)
Expand Down Expand Up @@ -182,18 +190,6 @@ func extractAuthor(htmlString string) string {
return ""
}

func isAuthorAccepted(author string) bool {
if len(acceptAuthors) == 0 {
return false
}
for _, accepted := range acceptAuthors {
if author == accepted {
return true
}
}
return false
}

func extractDate(htmlString string) string {
re := regexp.MustCompile(`title="(2023[^"]*)"`)
matches := re.FindStringSubmatch(htmlString)
Expand Down Expand Up @@ -221,26 +217,15 @@ func extractDomain(htmlString string) string {
return ""
}

func containsInterestingTopic(text string) bool {
if len(interestingTopics) == 0 {
func isIncluded(text string, list []string, fullMatch bool) bool {
if len(list) == 0 {
return false
}
lowercaseText := strings.ToLower(text)
for _, topic := range interestingTopics {
if strings.Contains(lowercaseText, topic) {
for _, el := range list {
if fullMatch && strings.ToLower(el) == lowercaseText {
return true
}
}
return false
}

func containsInterestingDomains(url string) bool {
if len(interestingDomains) == 0 {
return false
}
lowercaseText := strings.ToLower(url)
for _, topic := range interestingDomains {
if strings.Contains(lowercaseText, topic) {
} else if strings.Contains(lowercaseText, strings.ToLower(el)) {
return true
}
}
Expand Down

0 comments on commit 08f31bd

Please sign in to comment.