feat: migrate codes from previous project
This commit is contained in:
57
main.go
57
main.go
@@ -1,20 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"rss-to-feishu-next/internal/config"
|
||||
"rss-to-feishu-next/internal/feishu"
|
||||
"rss-to-feishu-next/internal/net"
|
||||
"rss-to-feishu-next/internal/rss"
|
||||
"rss-to-feishu-next/internal/silicon"
|
||||
"strings"
|
||||
|
||||
lark "github.com/larksuite/oapi-sdk-go/v3"
|
||||
)
|
||||
|
||||
// TIP <p>To run your code, right-click the code and select <b>Run</b>.</p> <p>Alternatively, click
|
||||
// the <icon src="AllIcons.Actions.Execute"/> icon in the gutter and select the <b>Run</b> menu item from here.</p>
|
||||
func main() {
|
||||
//TIP <p>Press <shortcut actionId="ShowIntentionActions"/> when your caret is at the underlined text
|
||||
// to see how GoLand suggests fixing the warning.</p><p>Alternatively, if available, click the lightbulb to view possible fixes.</p>
|
||||
s := "gopher"
|
||||
fmt.Printf("Hello and welcome, %s!\n", s)
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for i := 1; i <= 5; i++ {
|
||||
//TIP <p>To start your debugging session, right-click your code in the editor and select the Debug option.</p> <p>We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.</p>
|
||||
fmt.Println("i =", 100/i)
|
||||
ctx := context.Background()
|
||||
|
||||
netCli := net.NewClient()
|
||||
rssCli := rss.NewClient(netCli)
|
||||
siliconCli := silicon.NewClient(netCli)
|
||||
|
||||
larkCli := lark.NewClient(cfg.Feishu.AppID, cfg.Feishu.AppSecret)
|
||||
feishuCli := feishu.NewClient(larkCli)
|
||||
|
||||
messages, err := rssCli.FetchAllRss(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for i := 0; i < len(messages); i++ {
|
||||
prompt := cfg.Subscribes[i].Prompt + "\n" + messages[i].Content
|
||||
model := cfg.Subscribes[i].Model
|
||||
resp, err := siliconCli.FetchModelResponse(ctx, prompt, model)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var parts []string
|
||||
for _, item := range resp.Content {
|
||||
parts = append(parts, item.Text)
|
||||
}
|
||||
|
||||
allContent := strings.Join(parts, "\n")
|
||||
|
||||
message := fmt.Sprintf("%s\n%s\n%s", messages[i].Name, messages[i].Url, allContent)
|
||||
if err := feishuCli.SendMessageToChat(ctx, message, cfg.Feishu.ChatID); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user