Browse Source

Add send to VK

main
parent
commit
05b819b66c
  1. 3
      .gitignore
  2. 5
      go.mod
  3. 19
      go.sum
  4. 49
      main.go

3
.gitignore vendored

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
*.yml
main
*.xml
ssender
ssender
*.db

5
go.mod

@ -3,9 +3,14 @@ module mod @@ -3,9 +3,14 @@ module mod
go 1.17
require (
github.com/SevereCloud/vksdk/v2 v2.13.1 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/klauspost/compress v1.14.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

19
go.sum

@ -1,11 +1,30 @@ @@ -1,11 +1,30 @@
github.com/SevereCloud/vksdk/v2 v2.13.1 h1:D11NaP275mW01v2hRF0ycDHdJaIyZEvasZV4MSkg5Sk=
github.com/SevereCloud/vksdk/v2 v2.13.1/go.mod h1:UyOgSj/CYt2dByu3Fyf/y1yT1NoahVi4zECvvrbtPU4=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/klauspost/compress v1.14.2 h1:S0OHlFk/Gbon/yauFJ4FfJJF5V0fc5HbBTJazi28pRw=
github.com/klauspost/compress v1.14.2/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

49
main.go

@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
"log"
"os"
"github.com/SevereCloud/vksdk/v2/api"
"github.com/boltdb/bolt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/jessevdk/go-flags"
@ -23,8 +24,9 @@ type Config struct { @@ -23,8 +24,9 @@ type Config struct {
Token string `yaml:"token"`
} `yaml:"telegram"`
VK struct {
Send bool `yaml:"send"`
Token string `yaml:"token"`
Send bool `yaml:"send"`
Token string `yaml:"token"`
OwnerId int64 `yaml:"ownerid"`
} `yaml:"vk"`
Facebook struct {
Send bool `yaml:"send"`
@ -166,29 +168,42 @@ func InitDb(rss Rss2, dbpath string) { @@ -166,29 +168,42 @@ func InitDb(rss Rss2, dbpath string) {
}
func (config Config) RunSend() {
if config.Telegram.Send {
log.Println("Send to telegram")
bot, err := tgbotapi.NewBotAPI(config.Telegram.Token)
if err != nil {
log.Panic(err)
}
bot.Debug = config.Telegram.SendDebug
for _, v := range senditems.ItemList {
for _, v := range senditems.ItemList {
if config.Telegram.Send {
log.Println("Send to telegram")
bot, err := tgbotapi.NewBotAPI(config.Telegram.Token)
if err != nil {
log.Panic(err)
}
bot.Debug = config.Telegram.SendDebug
s := "<b>" + string(v.Title) + "</b>\n" + html.UnescapeString(string(v.Description)) +
"\n" + v.Link
msg := tgbotapi.NewMessage(config.Telegram.ChatId, s)
msg.ParseMode = "Html"
_, err := bot.Send(msg)
_, err = bot.Send(msg)
if err != nil {
log.Panic(err)
}
log.Println("Sended to telegram")
}
if config.VK.Send {
log.Println("Send to VK")
vk := api.NewVK(config.VK.Token)
_, err := vk.WallPost(api.Params{
"owner_id": config.VK.OwnerId,
"attachments": v.Link,
})
if err != nil {
log.Fatal(err)
}
log.Println("Sended to VK")
}
if config.Facebook.Send {
log.Println("Send to Facebook")
log.Println("Sending to facebook is not implemented yet")
}
}
if config.VK.Send {
log.Println("Send to VK")
}
if config.Facebook.Send {
log.Println("Send to Facebook")
}
}

Loading…
Cancel
Save