Commit ae4fbfc1a3b8

Vincent Demeester <vincent@sbr.pm>
2024-06-13 12:04:40
tools/go-org-readwise: remove org dependency
It doesn't fullfill my need, so I'll handle this my way, and in a very simple fashion. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent cf02432
Changed files (3)
tools
go-org-readwise
tools/go-org-readwise/internal/org/org.go
@@ -2,11 +2,12 @@ package org
 
 import (
 	"context"
+	"errors"
 	"fmt"
+	"os"
 	"regexp"
 	"strings"
 
-	"github.com/niklasfasching/go-org/org"
 	"github.com/vdemeester/home/tools/go-org-readwise/internal/readwise"
 )
 
@@ -41,6 +42,16 @@ func Sync(ctx context.Context, target string, results []readwise.Result) error {
 		// use a regexp to "detect" part of the thing.
 		filename := denoteFilename(result)
 		fmt.Println("file", filename)
+		if _, err := os.Stat(filename); err == nil {
+			// Append to the file
+			return errors.New("Not implemented")
+		} else if errors.Is(err, os.ErrNotExist) {
+			// Create the file
+		} else {
+			// Schrodinger: file may or may not exist. See err for details.
+			// Therefore, do *NOT* use !os.IsNotExist(err) to test for file existence
+			return err
+		}
 	}
 	return nil
 }
@@ -106,7 +117,3 @@ func sluggify(s string) string {
 	s = strings.TrimSuffix(s, "-")
 	return s
 }
-
-func Foo() {
-	org.New()
-}
tools/go-org-readwise/go.mod
@@ -1,11 +1,3 @@
 module github.com/vdemeester/home/tools/go-org-readwise
 
 go 1.22
-
-require github.com/niklasfasching/go-org v1.7.0
-
-require (
-	github.com/alecthomas/chroma/v2 v2.5.0 // indirect
-	github.com/dlclark/regexp2 v1.4.0 // indirect
-	golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
-)
tools/go-org-readwise/main.go
@@ -14,6 +14,11 @@ import (
 )
 
 func main() {
+	// for _, n := range d.Nodes {
+	// 	fmt.Printf("%+v\n", n)
+	// }
+
+	os.Exit(1)
 	apiKeyFile := flag.String("apiKeyFile", "", "File to load the apiKey from. If empty, it will defer to the READWISE_KEY environment variable")
 	targetFolder := flag.String("targetFolder", "", "Folder to write highlights (in org file) into")
 	flag.Parse()