Example #1
0
File: main.go Project: nmeum/cpod
func main() {
	flag.Parse()
	if *version {
		logger.Fatal(appVersion)
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), appName)
	lockPath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-%s", appName, util.Username()))

	if err := util.Lock(lockPath); os.IsExist(err) {
		logger.Fatalf("database is locked, remove %q to force unlock\n", lockPath)
	} else if err != nil {
		logger.Fatal(err)
	}

	storage, err := store.Load(filepath.Join(storeDir, "urls"))
	if err != nil {
		logger.Fatal(err)
	}

	update(storage)
	if err := os.Remove(lockPath); err != nil {
		logger.Fatal(err)
	}
}
Example #2
0
File: main.go Project: nmeum/cpod
func main() {
	if len(os.Args) <= 1 {
		usage()
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), "cpod")
	if err := os.MkdirAll(storeDir, 0755); err != nil {
		panic(err)
	}

	store, err := store.Load(filepath.Join(storeDir, "urls"))
	if err != nil && !os.IsNotExist(err) {
		panic(err)
	}

	outlines, err := load(os.Args)
	if err != nil {
		panic(err)
	}

	for _, outline := range outlines {
		url := outline.URL
		if !store.Contains(url) {
			store.Add(url)
		}
	}

	if err = store.Save(); err != nil {
		panic(err)
	}
}
Example #3
0
File: main.go Project: nmeum/cpod
func main() {
	if len(os.Args) <= 1 {
		usage()
	}

	storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), "cpod")
	storage, err := store.Load(filepath.Join(storeDir, "urls"))
	if err != nil {
		panic(err)
	}

	var wg sync.WaitGroup
	opmlFile := opml.Create(title)

	for cast := range storage.Fetch() {
		wg.Add(1)
		go func(p store.Podcast) {
			defer wg.Done()
			if p.Error != nil {
				fmt.Fprintf(os.Stderr, "%s\n", p.Error)
				return
			}

			feed := p.Feed
			opmlFile.Add(feed.Title, feed.Type, p.URL)
		}(cast)
	}

	wg.Wait()
	if err = opmlFile.Save(os.Args[1]); err != nil {
		panic(err)
	}
}