From 963b358c6189a13860775a36236ea743acdbeabc Mon Sep 17 00:00:00 2001 From: Bilal Khan Date: Tue, 18 Jun 2024 17:30:50 +0500 Subject: [PATCH] removed the script and the write notification method --- cmd/root.go | 2 +- interfaces/interfaces.go | 1 - logfile.log | 0 script.sh | 23 ---------- usecases/app/alert/alert.go | 74 ------------------------------ usecases/app/spend/notification.go | 2 +- 6 files changed, 2 insertions(+), 100 deletions(-) delete mode 100644 logfile.log delete mode 100644 script.sh diff --git a/cmd/root.go b/cmd/root.go index 5bca26e..b3af482 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v0.1.130" +const version = "v0.1.131" // rootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ diff --git a/interfaces/interfaces.go b/interfaces/interfaces.go index e2d2ede..a2a13e9 100644 --- a/interfaces/interfaces.go +++ b/interfaces/interfaces.go @@ -81,7 +81,6 @@ type ManageAlerts interface { AlertSetup(av *entities.AlertVariables) error SendAlert(category string) error SendNotification(category string) error - WriteNotificationValues(av *entities.AlertVariables) error } type AlertDB interface { diff --git a/logfile.log b/logfile.log deleted file mode 100644 index e69de29..0000000 diff --git a/script.sh b/script.sh deleted file mode 100644 index 2666f61..0000000 --- a/script.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# Desired time in HH:MM format -DESIRED_TIME="21:11" - -DESIRED_DAY="17" - -DESIRED_WEEKDAY="Monday" - -# Get the current time in HH:MM format -CURRENT_TIME=$(date +"%H:%M") - -CURRENT_DAY=$(date +"%d") - -CURRENT_WEEKDAY=$(date +"%A") - -# Check if the current time matches the desired time -if [ "$CURRENT_TIME" == "$DESIRED_TIME" ] && [ "$CURRENT_WEEKDAY" == "$DESIRED_WEEKDAY" ]; then - # Run your command and log the output - echo "$(date): It's time! Running the desired command." -else - echo "not set ${CURRENT_WEEKDAY} ${CURRENT_TIME} ${CURRENT_DAY}" -fi \ No newline at end of file diff --git a/usecases/app/alert/alert.go b/usecases/app/alert/alert.go index 84a6205..7f832da 100644 --- a/usecases/app/alert/alert.go +++ b/usecases/app/alert/alert.go @@ -4,10 +4,8 @@ import ( "errors" "fmt" "log" - "os" "strings" "time" - "unicode" "github.com/ibilalkayy/flow/entities" "github.com/ibilalkayy/flow/handler" @@ -88,24 +86,12 @@ func (h MyAlert) SendAlert(category string) error { return errors.New("wrong weekday is selected") } - values := entities.AlertVariables{ - Category: category, - Hours: hour, - Minutes: minute, - Days: day, - Weekdays: weekdayStr, - } - switch method { case "email": switch frequency { case "hourly": h.Deps.SpendAmount.HourlyNotification(category) case "daily": - err := h.Deps.ManageAlerts.WriteNotificationValues(&values) - if err != nil { - log.Fatal(err) - } h.Deps.SpendAmount.DailyNotification(hour, minute, category) case "weekly": h.Deps.SpendAmount.WeeklyNotification(weekday, hour, minute, category) @@ -120,66 +106,6 @@ func (h MyAlert) SendAlert(category string) error { return nil } -func (h MyAlert) WriteNotificationValues(av *entities.AlertVariables) error { - hours := av.Hours - minutes := av.Minutes - - desiredDay := av.Days - desiredWeekday := av.Weekdays - desiredTime := fmt.Sprintf("%02d:%02d", hours, minutes) - - // Convert to upper letter - if len(desiredWeekday) > 0 { - desiredWeekday = string(unicode.ToUpper(rune(desiredWeekday[0]))) + strings.ToLower(desiredWeekday[1:]) - } - - scriptPath := os.Getenv("SCRIPT_PATH") - if scriptPath == "" { - return errors.New("SCRIPT_PATH environment variable is not set") - } - scriptFile := fmt.Sprintf("%s/script.sh", scriptPath) - - input, err := os.ReadFile(scriptFile) - if err != nil { - log.Fatal(err) - } - - value, err := h.Deps.AlertDB.ViewAlert(av.Category) - if err != nil { - return err - } - - category, ok := value[1].(string) - if !ok { - return errors.New("unable to convert to string") - } - - if len(av.Category) != 0 && av.Category == category { - lines := strings.Split(string(input), "\n") - for i, line := range lines { - if strings.Contains(line, "DESIRED_TIME=") { - lines[i] = fmt.Sprintf(`DESIRED_TIME="%s"`, desiredTime) - } - if strings.Contains(line, "DESIRED_DAY=") { - lines[i] = fmt.Sprintf(`DESIRED_DAY="%d"`, desiredDay) - } - if strings.Contains(line, "DESIRED_WEEKDAY=") { - lines[i] = fmt.Sprintf(`DESIRED_WEEKDAY="%s"`, desiredWeekday) - } - } - - output := strings.Join(lines, "\n") - err = os.WriteFile(scriptFile, []byte(output), 0644) - if err != nil { - return err - } - } else { - return errors.New("category is not present in the alert") - } - - return nil -} - func (h MyAlert) SendNotification(category string) error { budgetDetails, err := h.Deps.ManageBudget.ViewBudget(category) if err != nil { diff --git a/usecases/app/spend/notification.go b/usecases/app/spend/notification.go index b90d98d..149361c 100644 --- a/usecases/app/spend/notification.go +++ b/usecases/app/spend/notification.go @@ -6,7 +6,7 @@ import ( ) func (h MySpending) HourlyNotification(category string) { - ticker := time.NewTicker(time.Second) + ticker := time.NewTicker(time.Hour) defer ticker.Stop() for { <-ticker.C