Remove HN comments
This commit is contained in:
parent
c4d917bada
commit
180fdece99
56
main.go
56
main.go
|
@ -1,9 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/namsral/flag"
|
"github.com/namsral/flag"
|
||||||
|
@ -25,64 +23,10 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateHnComment(id int, sats int, nComments int) string {
|
|
||||||
lnInvoiceDocs := "https://docs.lightning.engineering/the-lightning-network/payment-lifecycle/understanding-lightning-invoices"
|
|
||||||
return fmt.Sprintf(
|
|
||||||
""+
|
|
||||||
"Your post received %d sats and %d comments on %s [0].\n\n"+
|
|
||||||
"To claim your sats, reply to this comment with a LN address or invoice [1].\n\n"+
|
|
||||||
"You can create a SN account to obtain a LN address.\n"+
|
|
||||||
"\n\n"+
|
|
||||||
"[0] %s/r/%s (referral link)\n\n"+
|
|
||||||
"[1] %s",
|
|
||||||
sats,
|
|
||||||
nComments,
|
|
||||||
StackerNewsUrl,
|
|
||||||
StackerNewsItemLink(id),
|
|
||||||
SnUserName,
|
|
||||||
lnInvoiceDocs,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GenerateSnReply(sats int, nComments int) string {
|
|
||||||
return fmt.Sprintf("Notified OP on HN that their post received %d sats and %d comments.", sats, nComments)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
stories := FetchHackerNewsTopStories()
|
stories := FetchHackerNewsTopStories()
|
||||||
filtered := CurateContentForStackerNews(&stories)
|
filtered := CurateContentForStackerNews(&stories)
|
||||||
for _, story := range *filtered {
|
for _, story := range *filtered {
|
||||||
PostStoryToStackerNews(&story)
|
PostStoryToStackerNews(&story)
|
||||||
}
|
}
|
||||||
|
|
||||||
items := FetchStackerNewsUserItems(SnUserName)
|
|
||||||
now := time.Now()
|
|
||||||
for _, item := range *items {
|
|
||||||
duration := now.Sub(item.CreatedAt)
|
|
||||||
if duration >= 24*time.Hour && item.Sats > 0 {
|
|
||||||
log.Printf("Found SN item (id=%d) older than 24 hours with %d sats and %d comments\n", item.Id, item.Sats, item.NComments)
|
|
||||||
for _, comment := range item.Comments {
|
|
||||||
if comment.User.Name == SnUserName {
|
|
||||||
snReply := GenerateSnReply(item.Sats, item.NComments)
|
|
||||||
// Check if OP on HN was already notified
|
|
||||||
alreadyNotified := false
|
|
||||||
for _, comment2 := range comment.Comments {
|
|
||||||
if comment2.User.Name == SnUserName {
|
|
||||||
alreadyNotified = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if alreadyNotified {
|
|
||||||
log.Println("OP on HN was already notified")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
text := comment.Text
|
|
||||||
hnItemId := FindHackerNewsItemId(text)
|
|
||||||
hnComment := GenerateHnComment(item.Id, item.Sats, item.NComments)
|
|
||||||
CommentHackerNewsStory(hnComment, hnItemId)
|
|
||||||
CommentStackerNewsPost(snReply, comment.Id)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue