Переворошил файлы (опять), закинул всё в докер
This commit is contained in:
parent
be76c08756
commit
c853cfb592
11 changed files with 135 additions and 54 deletions
35
service/go.mod
Normal file
35
service/go.mod
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
module kiki/kiki
|
||||
|
||||
go 1.24.2
|
||||
|
||||
replace kiki/config => ../config
|
||||
|
||||
replace kiki/stacker => ../stacker
|
||||
|
||||
replace kiki/tooter => ../tooter
|
||||
|
||||
require (
|
||||
github.com/mattn/go-mastodon v0.0.9
|
||||
github.com/urfave/cli/v3 v3.2.0
|
||||
kiki/config v0.0.0-00010101000000-000000000000
|
||||
kiki/stacker v0.0.0-00010101000000-000000000000
|
||||
kiki/tooter v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.8.0 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/gorilla/websocket v1.5.1 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mmcdole/gofeed v1.3.0 // indirect
|
||||
github.com/mmcdole/goxpp v1.1.1-0.20240225020742-a0c311522b23 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/redis/go-redis/v9 v9.7.3 // indirect
|
||||
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
|
||||
golang.org/x/net v0.39.0 // indirect
|
||||
golang.org/x/text v0.24.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
95
service/kiki.go
Normal file
95
service/kiki.go
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"kiki/config"
|
||||
"kiki/stacker"
|
||||
"kiki/tooter"
|
||||
|
||||
"github.com/mattn/go-mastodon"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd := &cli.Command{
|
||||
Name: "kiki",
|
||||
Usage: "Ретранслятор из RSS в Mastodon. Когда-нибудь...",
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "init",
|
||||
Usage: "Инициализировать клиента",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
confFile, err := filepath.Abs("config.yaml")
|
||||
kikiConfig := config.GetKikiConfig(confFile)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
instanceUrlParser, err := url.Parse(kikiConfig.Instance)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
instanceUrlParser.Scheme = "https"
|
||||
|
||||
tooter.ClientConfiguration(instanceUrlParser.String())
|
||||
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "run",
|
||||
Usage: "Запуск транслятора",
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
mastoClient := mastodon.NewClient(config.GetSecrets("secret.conf"))
|
||||
|
||||
confFile, err := filepath.Abs("config.yaml")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
kikiConfig := config.GetKikiConfig(confFile)
|
||||
|
||||
rdb := stacker.ConnectToRedis(kikiConfig.Redis.Address)
|
||||
defer stacker.SaveRedis(rdb)
|
||||
|
||||
ticker := time.NewTicker(1 * time.Minute)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
|
||||
newPosts := tooter.NewsText(kikiConfig.RSSUri)
|
||||
|
||||
for _, post := range newPosts {
|
||||
inStack, err := stacker.CheckInRedis(rdb, post.GUID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
if !inStack {
|
||||
log.Println(post.Description)
|
||||
|
||||
toot, err := tooter.CreateToot(*mastoClient, post)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
tooter.CreatePost(*mastoClient, toot)
|
||||
|
||||
stacker.SetToRedis(rdb, post.GUID, post.Description)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue