summaryrefslogtreecommitdiff
path: root/doClean.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-01 20:14:28 -0500
committerJeff Carr <[email protected]>2025-09-01 20:14:28 -0500
commit8220d1817c35e7ac97830d64722050fa64978fdf (patch)
treed2cd5846811d21e4c1d5261183926325569d6700 /doClean.go
parent26d674c800eff651fb174484da39ddf3eddcd33b (diff)
working on processing JSON files
Diffstat (limited to 'doClean.go')
-rw-r--r--doClean.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/doClean.go b/doClean.go
new file mode 100644
index 0000000..e4c9783
--- /dev/null
+++ b/doClean.go
@@ -0,0 +1,87 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+func doClean() {
+ log.Info("find all files")
+ scanTmp()
+}
+
+func scanTmp() {
+ var count int
+ filepath.WalkDir("/tmp", func(path string, d os.DirEntry, err error) error {
+ if err != nil {
+ // Handle possible errors, like permission issues
+ // fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
+ // ignore all these problems
+ return err
+ }
+
+ /*
+ if d.IsDir() {
+ // log.Info("path is dir", path)
+ return nil
+ }
+ */
+
+ _, fname := filepath.Split(path)
+ if !strings.HasPrefix(fname, "regex.") {
+ return nil
+ }
+ if count > 5 {
+ return log.Errorf("count exceeded")
+ }
+ if strings.HasPrefix(fname, "regex.gemini-api-response") {
+ // log.Info("response file:", fname)
+ return nil
+ }
+ if strings.Contains(fname, "gemini-api-request") {
+ // log.Info("response file:", fname)
+ if err := cleanGeminiFile(path); err == nil {
+ count += 1
+ return nil
+ } else {
+ return nil
+ }
+ }
+ if strings.HasSuffix(fname, ".stats") {
+ cleanStatsFile(path)
+ return nil
+ }
+ log.Info("check file:", path)
+ return nil
+ })
+}
+
+func cleanStatsFile(fullname string) {
+ log.Info("stats file", fullname)
+}
+
+func cleanGeminiFile(fullname string) error {
+ _, fname := filepath.Split(fullname)
+ if !strings.HasSuffix(fname, ".json") {
+ return log.Errorf("not really gemini-api-request .json")
+ }
+ parts := strings.Split(fname, ".")
+ if len(parts) == 5 {
+ if parts[2] != "gemini-api-request" {
+ return log.Errorf("not really gemini-api-request")
+ }
+ }
+ uuid := parts[1]
+ for _, chat := range me.chats.GetChats() {
+ // log.Info(i, chat.Uuid)
+ if chat.Uuid == uuid {
+ log.Info("found uuid", uuid)
+ return nil
+ }
+ }
+ log.Info("gemini JSON file uuid not found", uuid)
+ return log.Errorf("gemini JSON file uuid %s not found", uuid)
+}