aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-02-26 11:41:08 -0700
committernytpu <alex@nytpu.com>2021-02-26 11:41:08 -0700
commit626ab3348f8145b1f8000fdc5dbd5b5250e887e4 (patch)
treec274e69d0562587833d30f46f94132bfee79b439
parentwrite to gemini file (diff)
downloadcheetah-bot-626ab3348f8145b1f8000fdc5dbd5b5250e887e4.tar.bz2
cheetah-bot-626ab3348f8145b1f8000fdc5dbd5b5250e887e4.zip
fix gemini file writing
-rw-r--r--cheetah-bot.go44
1 files changed, 30 insertions, 14 deletions
diff --git a/cheetah-bot.go b/cheetah-bot.go
index e605a68..d11d6a2 100644
--- a/cheetah-bot.go
+++ b/cheetah-bot.go
@@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"time"
-
/*
// imgur stuff
"github.com/koffeinsource/go-imgur"
@@ -104,34 +103,51 @@ func main() {
curYear, curMonth, curDay := time.Now().Date()
titleGemini := "# Cheetah a Day\n\n"
- linkGemini := fmt.Sprintf("=> D%03d.jpg %04d-%02d-%02d - Day %[4]d: %s\n", curYear, curMonth, curDay, day, description)
+ linkGemini := fmt.Sprintf("=> D%03d.jpg %04d-%02d-%02d - Day %[1]d: %[5]s", day, curYear, curMonth, curDay, description)
// do the final culminating posts
- geminiOrig, err := os.Open("/var/local/cheetahs/cheetahs.gmi")
+ geminiOrig, err := os.Open("/var/gemini/nytpu.com/cheetahs/index.gmi")
if err != nil {
fmt.Println("Failed to open file: ", err)
os.Exit(1)
}
defer geminiOrig.Close()
- geminiNew, err := os.OpenFile("/var/local/cheetahs/cheetahs.gmi.new", os.O_RDWR|os.O_CREATE, 0666)
+ geminiNew, err := os.OpenFile("/var/gemini/nytpu.com/cheetahs/index.gmi.new", os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
fmt.Println("Failed to open file: ", err)
os.Exit(1)
}
defer geminiNew.Close()
- reader := bufio.NewReader(geminiOrig)
- writer := bufio.NewWriter(geminiNew)
io.WriteString(geminiNew, titleGemini)
io.WriteString(geminiNew, linkGemini)
- _, _ = reader.ReadString('\n')
- _, _ = reader.ReadString('\n')
- _, err = io.Copy(writer, reader)
+ reader := bufio.NewReader(geminiOrig)
+ row1, err := reader.ReadSlice('\n')
+ if err != nil {
+ fmt.Println("Failed to get 1st line in file: ", err)
+ os.Exit(1)
+ }
+ row2, err := reader.ReadSlice('\n')
+ if err != nil {
+ fmt.Println("Failed to get 2nd line in file: ", err)
+ os.Exit(1)
+ }
+ _, err = geminiOrig.Seek(int64(len(row1)+len(row2)), io.SeekStart)
+ if err != nil {
+ fmt.Println("Failed to seek in file: ", err)
+ os.Exit(1)
+ }
+ _, err = io.Copy(geminiNew, geminiOrig)
if err != nil {
fmt.Println("Failed to update gemini file: ", err)
os.Exit(1)
}
+ err = os.Rename("/var/gemini/nytpu.com/cheetahs/index.gmi.new", "/var/gemini/nytpu.com/cheetahs/index.gmi")
+ if err != nil {
+ fmt.Println("Failed to move file: ", err)
+ os.Exit(1)
+ }
- //reddit.PostLink("nytpu", titleReddit, imgurImage)
+ //reddit.PostLink("nytpu", titleReddit, mastoImage.URL)
reddit.PostLink("Cheetahs", titleReddit, mastoImage.URL)
masto.PostStatus(titleMasto, 0, []int64{mastoImage.ID}, false, "", "public")
@@ -143,12 +159,12 @@ func main() {
os.Exit(1)
}
- err = os.Remove(filename)
+ err = os.Rename(filename, fmt.Sprintf("/var/gemini/nytpu.com/cheetahs/D%03d.jpg", day))
if err != nil {
- fmt.Printf("Failed to remove \"%v\": %v", filename, err)
+ fmt.Printf("Failed to rename \"%v\": %v", filename, err)
}
- err = os.Remove(descriptionFilename)
+ /*err = os.Remove(descriptionFilename)
if err != nil {
fmt.Printf("Failed to remove \"%v\": %v", filename, err)
- }
+ }*/
}