diff options
| author | Teddy Wing | 2017-06-03 11:45:53 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-03 11:45:53 +0200 | 
| commit | c0576d6d96656f4a83e8bdff7cb0a09f455a0b10 (patch) | |
| tree | 67959784f74f803e9c9528d246815e320f4d238c | |
| parent | 055301ca09d57b759b290d897bbb7560460251ca (diff) | |
| parent | d998a82d4019b1fc5a15734f091852b1b0f086d4 (diff) | |
| download | timetasker-c0576d6d96656f4a83e8bdff7cb0a09f455a0b10.tar.bz2 | |
Merge branch 'toml-projects-config' into timetasker-daily
| -rw-r--r-- | main.go | 54 | ||||
| -rw-r--r-- | timetask/fields.go | 166 | ||||
| -rw-r--r-- | timetask/http.go | 214 | 
3 files changed, 221 insertions, 213 deletions
| @@ -1,23 +1,22 @@  package main  import ( -	"fmt" -	"io/ioutil" +	// "fmt" +	// "io/ioutil"  	"log" -	"os" +	// "os"  	"github.com/teddywing/timetasker/timetask" -	"gopkg.in/yaml.v2" +	"github.com/BurntSushi/toml"  )  type Config struct {  	Auth struct {  		Username    string -		PasswordCmd string `yaml:"password_cmd"` +		PasswordCmd string  	} -	Fields   timetask.Fields -	Defaults timetask.TimeEntry +	Projects map[string]timetask.Project  }  var config Config @@ -25,34 +24,33 @@ var config Config  func main() {  	loadConfig() -	if len(os.Args) == 1 { -		fmt.Println("Not enough arguments") -		os.Exit(1) -	} - -	file_path := os.Args[len(os.Args)-1] -	file, err := ioutil.ReadFile(file_path) -	if err != nil { -		log.Println(err) -	} - -	time_entries := []timetask.TimeEntry{} -	err = yaml.Unmarshal(file, &time_entries) -	if err != nil { -		log.Println(err) -	} - -	log.Printf("%+v", time_entries) +	// if len(os.Args) == 1 { +	// 	fmt.Println("Not enough arguments") +	// 	os.Exit(1) +	// } +	// +	// file_path := os.Args[len(os.Args)-1] +	// file, err := ioutil.ReadFile(file_path) +	// if err != nil { +	// 	log.Println(err) +	// } + +	// time_entries := []timetask.TimeEntry{} +	// err = yaml.Unmarshal(file, &time_entries) +	// if err != nil { +	// 	log.Println(err) +	// } +	// +	// log.Printf("%+v", time_entries)  	// timetask.SubmitTimeEntries(config.Fields, time_entries) -	timetask.GenerateWeeklyTimesheet(os.Stdout, config.Defaults) +	// timetask.GenerateWeeklyTimesheet(os.Stdout, config.Defaults)  }  func loadConfig() { -	config_str, err := ioutil.ReadFile("config.yml")  	config = Config{} -	err = yaml.Unmarshal(config_str, &config) +	_, err := toml.DecodeFile("config2.toml", &config)  	if err != nil {  		log.Println(err)  	} diff --git a/timetask/fields.go b/timetask/fields.go index fb3a026..da2b37d 100644 --- a/timetask/fields.go +++ b/timetask/fields.go @@ -1,85 +1,95 @@  package timetask -import "fmt" +// import "fmt" -type Client struct { -	ID       int -	Name     string -	Projects []Project -} - -type Project struct { -	ID        int -	Name      string -	Modules   []Module -	Tasks     []Task -	WorkTypes []WorkType `yaml:"work_types"` -} - -type Module struct { -	ID   int -	Name string -} -type Task struct { -	ID   int -	Name string -} -type WorkType struct { -	ID   int -	Name string -} - -type Fields struct { -	PersonID int `yaml:"person_id"` -	Clients  []Client -} - -func (f *Fields) ClientByName(client_name string) (*Client, error) { -	for _, client := range f.Clients { -		if client.Name == client_name { -			return &client, nil -		} -	} +// type Client struct { +// 	ID       int +// 	Name     string +// 	Projects []Project +// } -	return nil, fmt.Errorf("Client %s not found", client_name) -} - -func (c *Client) ProjectByName(project_name string) (*Project, error) { -	for _, project := range c.Projects { -		if project.Name == project_name { -			return &project, nil -		} -	} - -	return nil, fmt.Errorf("Project %s not found", project_name) -} - -func (p *Project) ModuleByName(module_name string) (*Module, error) { -	for _, module := range p.Modules { -		if module.Name == module_name { -			return &module, nil -		} -	} +// type Project struct { +// 	ID        int +// 	Name      string +// 	Modules   []Module +// 	Tasks     []Task +// 	WorkTypes []WorkType `yaml:"work_types"` +// } -	return nil, fmt.Errorf("Module %s not found", module_name) -} - -func (p *Project) TaskByName(task_name string) (*Task, error) { -	for _, task := range p.Tasks { -		if task.Name == task_name { -			return &task, nil -		} -	} - -	return nil, fmt.Errorf("Task %s not found", task_name) +type Project struct { +	Client   int +	Project  int +	Module   int +	Task     int +	WorkType int +	Time     int +	Billable bool  } -func (p *Project) WorkTypeByName(work_type_name string) (*WorkType, error) { -	for _, work_type := range p.WorkTypes { -		if work_type.Name == work_type_name { -			return &work_type, nil -		} -	} - -	return nil, fmt.Errorf("Work type %s not found", work_type_name) -} +// type Module struct { +// 	ID   int +// 	Name string +// } +// type Task struct { +// 	ID   int +// 	Name string +// } +// type WorkType struct { +// 	ID   int +// 	Name string +// } +// +// type Fields struct { +// 	PersonID int `yaml:"person_id"` +// 	Clients  []Client +// } +// +// func (f *Fields) ClientByName(client_name string) (*Client, error) { +// 	for _, client := range f.Clients { +// 		if client.Name == client_name { +// 			return &client, nil +// 		} +// 	} +// +// 	return nil, fmt.Errorf("Client %s not found", client_name) +// } +// +// func (c *Client) ProjectByName(project_name string) (*Project, error) { +// 	for _, project := range c.Projects { +// 		if project.Name == project_name { +// 			return &project, nil +// 		} +// 	} +// +// 	return nil, fmt.Errorf("Project %s not found", project_name) +// } +// +// func (p *Project) ModuleByName(module_name string) (*Module, error) { +// 	for _, module := range p.Modules { +// 		if module.Name == module_name { +// 			return &module, nil +// 		} +// 	} +// +// 	return nil, fmt.Errorf("Module %s not found", module_name) +// } +// +// func (p *Project) TaskByName(task_name string) (*Task, error) { +// 	for _, task := range p.Tasks { +// 		if task.Name == task_name { +// 			return &task, nil +// 		} +// 	} +// +// 	return nil, fmt.Errorf("Task %s not found", task_name) +// } +// +// func (p *Project) WorkTypeByName(work_type_name string) (*WorkType, error) { +// 	for _, work_type := range p.WorkTypes { +// 		if work_type.Name == work_type_name { +// 			return &work_type, nil +// 		} +// 	} +// +// 	return nil, fmt.Errorf("Work type %s not found", work_type_name) +// } diff --git a/timetask/http.go b/timetask/http.go index 83946ad..94a1597 100644 --- a/timetask/http.go +++ b/timetask/http.go @@ -1,13 +1,13 @@  package timetask  import ( -	"fmt" -	"log" +	// "fmt" +	// "log"  	"net/http"  	"net/http/cookiejar"  	"net/url" -	"strconv" -	"strings" +	// "strconv" +	// "strings"  	"golang.org/x/net/publicsuffix"  ) @@ -36,106 +36,106 @@ func Login(username, password string) (resp *http.Response, err error) {  	return resp, err  } -func SubmitTimeEntries(fields Fields, time_entries []TimeEntry) (resp *http.Response, err error) { -	v := buildSubmissionParams(fields, time_entries) - -	v.Set("module", "time") -	v.Set("action", "submitmultipletime") - -	return nil, nil -} - -func buildSubmissionParams(fields Fields, time_entries []TimeEntry) url.Values { -	v := url.Values{} -	entry_indexes := []string{} - -	for i, entry := range time_entries { -		entry_indexes = append(entry_indexes, strconv.Itoa(i)) - -		client, err := fields.ClientByName(entry.Client) -		if err != nil { -			log.Panic(err) -		} - -		project, err := client.ProjectByName(entry.Project) -		if err != nil { -			log.Panic(err) -		} - -		module, err := project.ModuleByName(entry.Module) -		if err != nil { -			log.Panic(err) -		} - -		task, err := project.TaskByName(entry.Task) -		if err != nil { -			log.Panic(err) -		} - -		work_type, err := project.WorkTypeByName(entry.WorkType) -		if err != nil { -			log.Panic(err) -		} - -		var billable string -		if entry.Billable { -			billable = "t" -		} else { -			billable = "f" -		} - -		v.Set( -			fmt.Sprintf("f_personID%d", i), -			strconv.Itoa(fields.PersonID), -		) - -		v.Set( -			fmt.Sprintf("f_clientID%d", i), -			strconv.Itoa(client.ID), -		) - -		v.Set( -			fmt.Sprintf("f_projectID%d", i), -			strconv.Itoa(project.ID), -		) - -		v.Set( -			fmt.Sprintf("f_moduleID%d", i), -			strconv.Itoa(module.ID), -		) - -		v.Set( -			fmt.Sprintf("f_taskID%d", i), -			strconv.Itoa(task.ID), -		) - -		v.Set( -			fmt.Sprintf("f_worktypeID%d", i), -			strconv.Itoa(work_type.ID), -		) - -		v.Set( -			fmt.Sprintf("f_date%d", i), -			entry.Date.Format("02/01/06"), // day/month/year -		) - -		v.Set( -			fmt.Sprintf("f_time%d", i), -			strconv.Itoa(entry.Time), -		) - -		v.Set( -			fmt.Sprintf("f_billable%d", i), -			billable, -		) - -		v.Set( -			fmt.Sprintf("f_description%d", i), -			entry.Description, -		) -	} - -	v.Set("f_entryIndexes", strings.Join(entry_indexes, ",")) - -	return v -} +// func SubmitTimeEntries(fields Fields, time_entries []TimeEntry) (resp *http.Response, err error) { +// 	v := buildSubmissionParams(fields, time_entries) +// +// 	v.Set("module", "time") +// 	v.Set("action", "submitmultipletime") +// +// 	return nil, nil +// } +// +// func buildSubmissionParams(fields Fields, time_entries []TimeEntry) url.Values { +// 	v := url.Values{} +// 	entry_indexes := []string{} +// +// 	for i, entry := range time_entries { +// 		entry_indexes = append(entry_indexes, strconv.Itoa(i)) +// +// 		client, err := fields.ClientByName(entry.Client) +// 		if err != nil { +// 			log.Panic(err) +// 		} +// +// 		project, err := client.ProjectByName(entry.Project) +// 		if err != nil { +// 			log.Panic(err) +// 		} +// +// 		module, err := project.ModuleByName(entry.Module) +// 		if err != nil { +// 			log.Panic(err) +// 		} +// +// 		task, err := project.TaskByName(entry.Task) +// 		if err != nil { +// 			log.Panic(err) +// 		} +// +// 		work_type, err := project.WorkTypeByName(entry.WorkType) +// 		if err != nil { +// 			log.Panic(err) +// 		} +// +// 		var billable string +// 		if entry.Billable { +// 			billable = "t" +// 		} else { +// 			billable = "f" +// 		} +// +// 		v.Set( +// 			fmt.Sprintf("f_personID%d", i), +// 			strconv.Itoa(fields.PersonID), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_clientID%d", i), +// 			strconv.Itoa(client.ID), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_projectID%d", i), +// 			strconv.Itoa(project.ID), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_moduleID%d", i), +// 			strconv.Itoa(module.ID), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_taskID%d", i), +// 			strconv.Itoa(task.ID), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_worktypeID%d", i), +// 			strconv.Itoa(work_type.ID), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_date%d", i), +// 			entry.Date.Format("02/01/06"), // day/month/year +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_time%d", i), +// 			strconv.Itoa(entry.Time), +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_billable%d", i), +// 			billable, +// 		) +// +// 		v.Set( +// 			fmt.Sprintf("f_description%d", i), +// 			entry.Description, +// 		) +// 	} +// +// 	v.Set("f_entryIndexes", strings.Join(entry_indexes, ",")) +// +// 	return v +// } | 
