func GetProjects(filename string) ([]*scratch.Project, error) {

	file, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	projects := []*scratch.Project{}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		id := scanner.Text()
		p, err := scratch.GetProject(id)
		if err != nil {
			fmt.Println("Could not get project ", id)
			continue
		}
		projects = append(projects, p)
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}

	return projects, nil
}
Ejemplo n.º 2
0
func main() {
	id := "86536890"
	p, err := scratch.GetProject(id)

	fmt.Println(p, err)

	tags := []string{"kodeklubbentromso", "tromso"}

	projects := []*scratch.Project{}
	for _, tag := range tags {
		ps, err := scratch.GetProjects(tag)
		if err != nil {
			fmt.Println(err)
			return
		}
		projects = append(projects, ps...)
	}

	filename := "ids"
	f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
	if err != nil {
		panic(err)
	}

	defer f.Close()

	for _, p := range projects {
		fmt.Println(p)
		_, err = f.WriteString(strconv.Itoa(p.ID) + "\n")
		if err != nil {
			fmt.Println(err)
			return
		}
	}

	fmt.Println(projects, err)
}