コード例 #1
0
ファイル: util.go プロジェクト: erasche/gologme
func WriteStringFile(category string, windows []gologme.SEventT, dir string) {
	err := os.MkdirAll(dir, 0777)
	if err != nil {
		log.Fatal(err)
	}
	var (
		f            *os.File
		lastUlogTime int64
		init         bool = false
	)

	for _, wl := range windows {
		ult := gologme.Ulogme7amTime(wl.RealTime)
		if !init || ult != lastUlogTime {
			_ = f.Close()
			fn := fmt.Sprintf("%s/%s_%d.txt", dir, category, ult)
			fmt.Printf("Writing to %s\n", fn)
			f, err = os.Create(fn)
			if err != nil {
				log.Fatal(err)
			}
			lastUlogTime = ult
			init = true
		}
		f.WriteString(fmt.Sprintf("%d %s\n", wl.RealTime.Unix(), wl.Title))
	}
}
コード例 #2
0
ファイル: endpoints.go プロジェクト: erasche/gologme
// ExportList produces custom json struct required by ulogme UI
func ExportList(w http.ResponseWriter, r *http.Request, uid int) {
	minTime, maxTime := golog.RecordedDataRange()
	// add a day to maxTime
	maxTime.Add(time.Hour * 12)
	// Convert to u7am
	iminTime := util.Ulogme7amTime(minTime)
	imaxTime := util.Ulogme7amTime(maxTime)
	//{"fname": "/api/events/1448197200", "t0": 1448197200, "t1": 1448283600}
	eventList := make([]*eventListJSON, 0)
	var aDayInSeconds = int64((time.Hour * 24).Seconds())
	var i int64
	for i = iminTime; i < imaxTime; i += aDayInSeconds {
		eventList = append(eventList, &eventListJSON{
			FName: fmt.Sprintf("/api/events/%d", int(i)),
			T0:    int(i),
			T1:    int(i + aDayInSeconds),
		})
	}
	js, _ := json.MarshalIndent(eventList, "", "  ")
	w.Write(js)
}
コード例 #3
0
ファイル: util.go プロジェクト: erasche/gologme
func WriteNotes(notes []gologme.NoteEvent, dir string) {
	err := os.MkdirAll(dir, 0777)
	if err != nil {
		log.Fatal(err)
	}
	var (
		f            *os.File
		lastUlogTime int64
		init         bool = false
	)
	for _, note := range notes {
		ult := gologme.Ulogme7amTime(note.RealTime)
		if !init || ult != lastUlogTime {
			_ = f.Close()
			var fn string
			if note.Type == gologme.BLOG_TYPE {
				fn = fmt.Sprintf("%s/blog_%d.txt", dir, ult)
			} else {
				fn = fmt.Sprintf("%s/notes_%d.txt", dir, ult)
			}
			fmt.Printf("Writing to %s\n", fn)
			f, err = os.Create(fn)
			if err != nil {
				log.Fatal(err)
			}
			lastUlogTime = ult
			init = true
		}

		if note.Type == gologme.BLOG_TYPE {
			f.WriteString(fmt.Sprintf("%s", note.Contents))
		} else {
			f.WriteString(fmt.Sprintf("%d %s\n", note.RealTime.Unix(), note.Contents))
		}
	}
}