Exemple #1
0
func main() {
	var client *simplenote.Client
	parseFlags()
	args := flag.Args()
	if true {
		if len(args) != 3 {
			usage()
			return
		}
		client = simplenote.NewClient(args[0], args[1], args[2])
	} else {
		client = simplenote.NewClient("api_key", "*****@*****.**", "password")
	}

	notes, err := client.List()
	if err != nil {
		log.Fatalf("c.List() failed with '%s'\n", err)
	}
	for _, note := range notes {
		printNote(note)
		if !allVersions {
			continue
		}
		ver := note.Version - 1
		id := note.ID
		for ver > 0 {
			n, err := client.GetNote(id, ver)
			if err != nil {
				// sometimes older versions don't exist. there doesn't seeme to be
				// a way to list valid versions
				//log.Printf("api.GetNote() failed with '%s'\n", err)
			} else {
				printNote(n)
			}
			ver--
		}
	}
}
Exemple #2
0
func main() {
	var client *simplenote.Client
	parseFlags()
	args := flag.Args()
	if len(args) != 3 {
		usage()
		return
	}
	loadPreviousNotes()
	fmt.Printf("all versions: %v. Previously loaded: %d\n", flgAllVersions, len(previousNotes))
	file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
	if err != nil {
		log.Fatalf("os.OpenFile('%s') failed with '%s'\n", fileName, err)
	}
	defer file.Close()
	client = simplenote.NewClient(args[0], args[1], args[2])
	lgr := newLogger("log.txt")
	defer lgr.Close()
	if lgr != nil {
		client.Logger = lgr
	}

	notes, err := client.List()
	if err != nil {
		log.Fatalf("c.List() failed with '%s'\n", err)
	}
	nNotes := 0
	nNotesTotal := 0
	nVersions := 0
	nVersionsTotal := 0
	for _, note := range notes {
		id := note.ID

		if flgAllVersions {
			for ver := 1; ver < note.Version; ver++ {
				if wasImported2(id, ver) {
					nVersionsTotal++
					continue
				}
				n, err := client.GetNote(id, ver)
				if err != nil {
					// sometimes older versions don't exist. there doesn't seeme to be
					// a way to list valid versions
					//log.Printf("api.GetNote() failed with '%s'\n", err)
					continue
				}
				nVersionsTotal++
				nVersions++
				didWrite := writeNote(file, n)
				if !didWrite {
					log.Fatalf("unexpectedly didWrite on note %v\n", n)
				}
			}
		}
		didWrite := writeNote(file, note)
		nNotesTotal++
		if didWrite {
			nNotes++
		}
	}
	if flgAllVersions {
		fmt.Printf("Imported %d new notes and %d new versions, %d total notes, %d total versions\n", nNotes, nVersions, nNotesTotal, nVersionsTotal)

	} else {
		fmt.Printf("Imported %d new notes, %d total notes\n", nNotes, nNotesTotal)
	}
}