🌷 the cutsie hackatime helper
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: use join path and simplify some stuff

dunkirk.sh b35aaa79 0d8e88d9

verified
+8 -10
+8 -10
handler/main.go
··· 4 4 "errors" 5 5 "fmt" 6 6 "os" 7 + "path/filepath" 7 8 "runtime" 8 9 "strings" 9 10 "time" ··· 26 27 if err != nil { 27 28 return errors.New("somehow your user doesn't exist? fairly sure this should never happen; plz report this to @krn on slack or via email at me@dunkirk.sh") 28 29 } 29 - hackatime_path := user_dir + "/.wakatime.cfg" 30 + hackatime_path := filepath.Join(user_dir, ".wakatime.cfg") 30 31 31 - switch os_name { 32 - case "linux": 33 - case "darwin": 34 - case "windows": 35 - default: 32 + if os_name != "linux" && os_name != "darwin" && os_name != "windows" { 36 33 return errors.New("hmm you don't seem to be running a recognized os? you are listed as running " + styles.Fancy.Render(os_name) + "; can you plz report this to @krn on slack or via email at me@dunkirk.sh?") 37 34 } 38 35 ··· 62 59 return errors.New("hmm 🤔 looks like you don't have an api_url in your config file? are you sure you have followed the setup instructions at " + styles.Muted.Render("https://hackatime.hackclub.com/my/wakatime_setup") + " correctly?") 63 60 } 64 61 65 - if api_url != "https://hackatime.hackclub.com/api/hackatime/v1" { 62 + correctApiUrl := "https://hackatime.hackclub.com/api/hackatime/v1" 63 + if api_url != correctApiUrl { 66 64 if api_url == "https://api.wakatime.com/api/v1" { 67 65 client := wakatime.NewClient(api_key) 68 66 _, err := client.GetStatusBar() ··· 73 71 return errors.New("turns out your config is connected to the wrong api url and is trying to use wakatime.com to sync time but you don't have a working api key from them. Go to " + styles.Muted.Render("https://hackatime.hackclub.com/my/wakatime_setup") + " to run the setup script and fix your config file") 74 72 } 75 73 } 76 - c.Println("\nYour api url", styles.Muted.Render(api_url), "doesn't match the expected url of", styles.Muted.Render("https://hackatime.hackclub.com/api/hackatime/v1"), "however if you are using a custom forwarder or are sure you know what you are doing then you are probably fine") 74 + c.Println("\nYour api url", styles.Muted.Render(api_url), "doesn't match the expected url of", styles.Muted.Render(correctApiUrl), "however if you are using a custom forwarder or are sure you know what you are doing then you are probably fine") 77 75 } 78 76 79 77 client := wakatime.NewClientWithOptions(api_key, api_url) 78 + c.Println("\nChecking your coding stats for today...") 80 79 duration, err := client.GetStatusBar() 81 80 if err != nil { 82 81 if errors.Is(err, wakatime.ErrUnauthorized) { ··· 109 108 Branch: "main", 110 109 Category: "coding", 111 110 CursorPos: 1, 112 - Entity: user_dir + "/akami.txt", 111 + Entity: filepath.Join(user_dir, "akami.txt"), 113 112 Type: "file", 114 113 IsWrite: true, 115 114 Language: "Go", ··· 128 127 return nil 129 128 }, 130 129 } 131 - 132 130 }