Compare commits
	
		
			No commits in common. "67dc1775b2c2ab0ea89967e7cbb6a0cd6a6a9048" and "3e0b10a8f51a282b22a8cfc4e6a5342d4b741867" have entirely different histories.
		
	
	
		
			67dc1775b2
			...
			3e0b10a8f5
		
	
		
							
								
								
									
										27
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								README.md
									
									
									
									
									
								
							@ -1,7 +1,5 @@
 | 
			
		||||
# Go Task Reminder
 | 
			
		||||
 | 
			
		||||
***unfinished***
 | 
			
		||||
 | 
			
		||||
## The Goal
 | 
			
		||||
 | 
			
		||||
Create a **Task Reminder** application that will:
 | 
			
		||||
@ -19,32 +17,11 @@ Of course, handle all the errors that are involved with this:
 | 
			
		||||
The JSON structure should look like this:
 | 
			
		||||
 | 
			
		||||
```json
 | 
			
		||||
{
 | 
			
		||||
    "Tasks":
 | 
			
		||||
    [
 | 
			
		||||
        {
 | 
			
		||||
        "taskname": "Example Task",
 | 
			
		||||
        "taskdesc": "",
 | 
			
		||||
        "interval": 100,
 | 
			
		||||
        "cmd": "ls | wc -l" ,
 | 
			
		||||
        "icon": ""
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
        "taskname": "Second Example",
 | 
			
		||||
        "taskdesc": "catlol",
 | 
			
		||||
        "interval": 15,
 | 
			
		||||
        "cmd": "",
 | 
			
		||||
        "icon": "./assets/catlol.jpg"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## TODO
 | 
			
		||||
* Create sample config
 | 
			
		||||
* check these two locations for a config:
 | 
			
		||||
This file can be placed in either:
 | 
			
		||||
* /home/user/.config/rem/tasks.json
 | 
			
		||||
* /home/user/go/src/rem/tasks.json
 | 
			
		||||
* More!
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 36 KiB  | 
							
								
								
									
										3
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.go
									
									
									
									
									
								
							@ -16,5 +16,8 @@ func main() {
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Fprintf(os.Stderr, "Cannot load config file: %s\n\t%s\n", configFlag, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	TaskRun(*config)
 | 
			
		||||
	//exampleoutput := TaskCMD(*config)
 | 
			
		||||
	//fmt.Printf("%s", exampleoutput)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										39
									
								
								run.go
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								run.go
									
									
									
									
									
								
							@ -4,52 +4,30 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/gen2brain/beeep"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Run will take the config file and for each task, run a go routine
 | 
			
		||||
func TaskRun(c Config) {
 | 
			
		||||
	var wg sync.WaitGroup
 | 
			
		||||
 | 
			
		||||
	for i := range c.Tasks {
 | 
			
		||||
		title := c.Tasks[i].TaskName
 | 
			
		||||
		interval := c.Tasks[i].Interval
 | 
			
		||||
 | 
			
		||||
		var desc string
 | 
			
		||||
		// check if desc is empty and use the cmd output, if not just get the desc
 | 
			
		||||
		if c.Tasks[i].TaskDesc == "" {
 | 
			
		||||
			desc = TaskCMD(c.Tasks[i])
 | 
			
		||||
		} else {
 | 
			
		||||
			desc = c.Tasks[i].TaskDesc
 | 
			
		||||
		}
 | 
			
		||||
		asset := c.Tasks[i].Icon
 | 
			
		||||
 | 
			
		||||
		//run the commands with go func()!
 | 
			
		||||
		wg.Add(1)
 | 
			
		||||
		go func() {
 | 
			
		||||
			fmt.Printf("%s has time interval %d\n", title, interval)
 | 
			
		||||
			for range time.Tick(time.Second * interval) {
 | 
			
		||||
				err := beeep.Notify(title, desc, asset)
 | 
			
		||||
		desc := c.Tasks[i].TaskDesc
 | 
			
		||||
		err := beeep.Notify(title, desc, "")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Fprintf(os.Stderr, "ERROR: could not display \"%s\":\n\t%s\n", title, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
			wg.Done()
 | 
			
		||||
		}()
 | 
			
		||||
	}
 | 
			
		||||
	wg.Wait()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TaskCMD will take in a Task, run the command with bash and return the string output
 | 
			
		||||
func TaskCMD(t Task) (output string) {
 | 
			
		||||
	command := t.CMD
 | 
			
		||||
// TaskCMD will take the config struct and run all the "CMD" fields with "bash -c [command]" and return the output
 | 
			
		||||
func TaskCMD(c Config) (output string) {
 | 
			
		||||
	for i := range c.Tasks {
 | 
			
		||||
		command := c.Tasks[i].CMD
 | 
			
		||||
 | 
			
		||||
		if command == " " {
 | 
			
		||||
		fmt.Printf("INFO: Task %s has the cmd section empty. Will just return...\n", t.TaskName)
 | 
			
		||||
			fmt.Printf("INFO: Task %s has the cmd section empty. Will just return...\n", c.Tasks[i].TaskName)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -57,5 +35,8 @@ func TaskCMD(t Task) (output string) {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Fprintf(os.Stderr, "ERROR: could not run command \"%s\":\n\t%s\n", command, err)
 | 
			
		||||
		}
 | 
			
		||||
		//fmt.Printf("Output:\n%s\n", out)
 | 
			
		||||
		return string(out)
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								tasks.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tasks.go
									
									
									
									
									
								
							@ -1,13 +1,11 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import "time"
 | 
			
		||||
 | 
			
		||||
// TODO: Finish off doc. here
 | 
			
		||||
 | 
			
		||||
type Task struct {
 | 
			
		||||
	TaskName string `json:"taskname"`
 | 
			
		||||
	TaskDesc string `json:"taskdesc"`
 | 
			
		||||
	Interval time.Duration `json:"interval"`
 | 
			
		||||
	Interval int32  `json:"interval"`
 | 
			
		||||
	CMD      string `json:"cmd"`
 | 
			
		||||
	Icon     string `json:"icon"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								tasks.json
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								tasks.json
									
									
									
									
									
								
							@ -2,27 +2,19 @@
 | 
			
		||||
    "Tasks":
 | 
			
		||||
    [
 | 
			
		||||
        {
 | 
			
		||||
        "taskname": "Example ls | wc -l Task",
 | 
			
		||||
        "taskdesc": "",
 | 
			
		||||
        "interval": 6,
 | 
			
		||||
        "cmd": "ls /home/simon/ | wc -l" ,
 | 
			
		||||
        "taskname": "Example Task",
 | 
			
		||||
        "taskdesc": "This is placeholder",
 | 
			
		||||
        "interval": 100,
 | 
			
		||||
        "cmd": "we" ,
 | 
			
		||||
        "icon": " "
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
        "taskname": "Example with no cmd",
 | 
			
		||||
        "taskname": "Second Example",
 | 
			
		||||
        "taskdesc": "Still Place holder",
 | 
			
		||||
        "interval": 8,
 | 
			
		||||
        "interval": -1,
 | 
			
		||||
        "cmd": " ",
 | 
			
		||||
        "icon": " "
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
        "taskname": "Example image task",
 | 
			
		||||
        "taskdesc": "cat lol",
 | 
			
		||||
        "interval": 10,
 | 
			
		||||
        "cmd": "" ,
 | 
			
		||||
        "icon": "./assets/catlol.jpg"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user