summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--importexport.go132
-rw-r--r--interact.go22
-rw-r--r--utils.go10
3 files changed, 151 insertions, 13 deletions
diff --git a/importexport.go b/importexport.go
index 471a022..e1af448 100644
--- a/importexport.go
+++ b/importexport.go
@@ -2,9 +2,13 @@ package main
import (
"os"
- "github.com/atotto/encoding/csv"
- //"bufio"
- //"encoding/csv"
+ //"github.com/atotto/encoding/csv"
+ //"io"
+ _ "fmt"
+ "time"
+ "bufio"
+ "strconv"
+ "encoding/csv"
)
func ExportTasks(in []Task,filename string) {
@@ -15,7 +19,9 @@ func ExportTasks(in []Task,filename string) {
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
- w.WriteStruct(i)
+ str := []string{Sint(i.Id),Sint(i.Projectid),i.Start.Format(time.RFC3339),i.Stop.Format(time.RFC3339),i.Taskname,i.Comment,Sint(i.Checkout)}
+ w.Write(str)
+ //w.WriteStruct(i)
}
}
@@ -27,7 +33,10 @@ func ExportProjects(in []Project,filename string) {
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
- w.WriteStruct(i)
+ str := []string{Sint(i.Id),i.Name,i.Comment,i.First.Format(time.RFC3339),i.Last.Format(time.RFC3339),Sint(i.Finished),Sint(i.Customer)}
+ w.Write(str)
+ //w.Write([]string{" Fuck","Master","Flash"})
+ //w.WriteStruct(i)
}
}
@@ -39,6 +48,117 @@ func ExportCustomers(in []Customer,filename string) {
w := csv.NewWriter(file)
defer w.Flush()
for _,i := range in {
- w.WriteStruct(i)
+ str := []string{Sint(i.Id),i.Company,i.Name,i.Address,Sflo(i.Satz),i.Lastbill.Format(time.RFC3339)}
+ w.Write(str)
+ //w.WriteStruct(i)
}
}
+
+// Import an array of Tasks from a csv of given filename
+func ImportTasks(filename string) ([]Task) {
+ var tsk []Task
+ //w := NewReader(strings.NewReader())
+ f, _ := os.Open(filename)
+
+ // Create a new reader.
+ r := csv.NewReader(bufio.NewReader(f))
+ //err := r.ReadStructAll(&cust)
+ //checkErr(err)
+ lines, err := r.ReadAll()
+ checkErr(err)
+
+ for _, line := range lines {
+ id, err := strconv.Atoi(line[0])
+ checkErr(err)
+ pr, err := strconv.Atoi(line[1])
+ checkErr(err)
+ sta,err := time.Parse(time.RFC3339,line[2])
+ checkErr(err)
+ sto,err := time.Parse(time.RFC3339,line[3])
+ checkErr(err)
+ ch, err := strconv.Atoi(line[6])
+ checkErr(err)
+ data := Task{
+ Id: id,
+ Projectid: pr,
+ Start: sta,
+ Stop: sto,
+ Taskname: line[4],
+ Comment: line[5],
+ Checkout: ch,
+ }
+ tsk=append(tsk,data)
+
+ }
+ return tsk
+}
+
+// Import an array of Customers from a csv of given filename
+func ImportCustomers(filename string) ([]Customer) {
+ var cust []Customer
+ //w := NewReader(strings.NewReader())
+ f, _ := os.Open(filename)
+
+ // Create a new reader.
+ r := csv.NewReader(bufio.NewReader(f))
+ //err := r.ReadStructAll(&cust)
+ //checkErr(err)
+ lines, err := r.ReadAll()
+ checkErr(err)
+
+ for _, line := range lines {
+ id, err := strconv.Atoi(line[0])
+ checkErr(err)
+ sat,err := strconv.ParseFloat(line[4],64)
+ checkErr(err)
+ tim,err := time.Parse(time.RFC3339,line[5])
+ checkErr(err)
+ data := Customer{
+ Id: id,
+ Company: line[1],
+ Name: line[2],
+ Address: line[3],
+ Satz: sat,
+ Lastbill: tim,
+ }
+ cust=append(cust,data)
+ }
+ return cust
+}
+
+// Import an array of Projects from a csv of given filename
+func ImportProjects(filename string) (prjs []Project) {
+ //w := NewReader(strings.NewReader())
+ f, _ := os.Open(filename)
+
+ // Create a new reader.
+ r := csv.NewReader(bufio.NewReader(f))
+ //err := r.ReadStructAll(&cust)
+ //checkErr(err)
+ lines, err := r.ReadAll()
+ checkErr(err)
+
+ for _, line := range lines {
+ id, err := strconv.Atoi(line[0])
+ checkErr(err)
+ fir,err := time.Parse(time.RFC3339,line[3])
+ checkErr(err)
+ las,err := time.Parse(time.RFC3339,line[4])
+ checkErr(err)
+ fin,err := strconv.Atoi(line[5])
+ checkErr(err)
+ cu,err := strconv.Atoi(line[6])
+ checkErr(err)
+ data := Project{
+ Id: id,
+ Name: line[1],
+ Comment: line[2],
+ First: fir,
+ Last: las,
+ Finished: fin,
+ Customer: cu,
+ }
+ prjs=append(prjs,data)
+ }
+ return
+}
diff --git a/interact.go b/interact.go
index d09dd14..d0b3d71 100644
--- a/interact.go
+++ b/interact.go
@@ -501,9 +501,9 @@ func interact(fulldb bool) {
Func: func(c *ishell.Context) {
//multichoice("Geh scheissn")
- nm,st := GetTaskSums(currproject.Id)
- i := Multichoice("Sicha?",st)
- fmt.Println(nm[i])
+ //nm,st := GetTaskSums(currproject.Id)
+ //i := Multichoice("Sicha?",st)
+ //fmt.Println(nm[i])
prid := GetProjectIds()
cuid := GetCustomerIds()
taid := GetTaskIds()
@@ -513,15 +513,23 @@ func interact(fulldb bool) {
c.Println("Tasks:",len(tas))
c.Println("Projects:",len(prs))
c.Println("Customers:",len(cus))
- c.Println("Customers:",cus)
+ //c.Println("Customers:",cus)
ExportCustomers(cus,"export.customers")
ExportProjects(prs,"export.projects")
ExportTasks(tas,"export.tasks")
-
- icus := ImportCustomer("export.customers")
+
+ icus := ImportCustomers("export.customers")
c.Println("Imported Customers:",len(icus))
- c.Println("Customers:",icus)
+ //c.Println("Customers:",icus)
+
+ itas := ImportTasks("export.tasks")
+ c.Println("Imported Tasks:",len(itas))
+ //c.Println("Tasks:",itas)
+
+ iprs := ImportProjects("export.projects")
+ c.Println("Imported Projects:",len(iprs))
+ c.Println("Projects:",iprs)
},
})
diff --git a/utils.go b/utils.go
index 03ef940..c9b0aad 100644
--- a/utils.go
+++ b/utils.go
@@ -86,6 +86,16 @@ func frame(text string, head bool) (out string) {
return
}
+// return the int as a string
+func Sint(in int) (string) {
+ return fmt.Sprint(in)
+}
+
+// return the float as a string
+func Sflo(in float64) (string) {
+ return fmt.Sprintf("%.2f",in)
+}
+
func getGitTag() string {
var (
cmdOut []byte