-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (51 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"log/slog"
"os"
"github.com/lainio/err2/try"
"github.com/lauravuo/vegaanibotti/blog"
"github.com/lauravuo/vegaanibotti/bot"
"github.com/lauravuo/vegaanibotti/bot/img"
)
const (
boldFontFile = "./bot/img/font/Amatic_SC/AmaticSC-Bold.ttf"
regFontFile = "./bot/img/font/Amatic_SC/AmaticSC-Regular.ttf"
)
func main() {
fetchOnly := false
if len(os.Args) > 1 {
fetchOnly = os.Args[1] == "--fetch"
}
posts := try.To1(blog.FetchNewPosts(
fetchOnly,
))
if !fetchOnly {
chosenPost := blog.ChooseNextPost(posts, blog.UsedBlogsIDsPath)
slog.Info("Chosen post",
"title", chosenPost.Title,
"description", chosenPost.Description,
"url", chosenPost.URL)
// Generate and upload image
bucketURL := os.Getenv("CLOUD_BUCKET_URL")
imageFile, smallImageFile := img.GenerateThumbnail(
&chosenPost,
"./bot/img/vegaanibotti.png",
"image",
boldFontFile,
regFontFile,
)
paths := img.UploadToCloud([]string{imageFile, smallImageFile})
chosenPost.ImageURL = bucketURL + "/" + paths[0]
chosenPost.ThumbnailURL = bucketURL + "/" + paths[1]
m := bot.InitMastodon()
try.To(m.PostToMastodon(&chosenPost))
x := bot.InitX()
try.To(x.PostToX(&chosenPost))
f := bot.InitFB()
try.To(f.PostToFB(&chosenPost))
s := bot.InitSite()
try.To(s.PostToSite(&chosenPost))
i := bot.InitIG()
try.To(i.PostToIG(&chosenPost))
}
}