Esempio n. 1
0
File: main.go Progetto: nmeum/cpod
func getItem(cast feedparser.Feed, item feedparser.Item) error {
	title, err := util.Escape(cast.Title)
	if err != nil {
		return err
	}

	target := filepath.Join(downloadDir, title)
	if err := os.MkdirAll(filepath.Dir(target), 0755); err != nil {
		return err
	}

	fp, err := util.GetFile(item.Attachment, target)
	if err != nil {
		return err
	}

	name, err := util.Escape(item.Title)
	if err == nil {
		newfp := filepath.Join(target, name+filepath.Ext(fp))
		if err = os.Rename(fp, newfp); err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 2
0
File: main.go Progetto: nmeum/cpod
func readMarker(name string) (marker time.Time, err error) {
	name, err = util.Escape(name)
	if err != nil {
		return
	}

	file, err := os.Open(filepath.Join(downloadDir, name, ".latest"))
	if err != nil {
		return
	}

	defer file.Close()
	var timestamp int64

	if _, err = fmt.Fscanf(file, "%d\n", &timestamp); err != nil {
		return
	}

	marker = time.Unix(timestamp, 0)
	return
}
Esempio n. 3
0
File: main.go Progetto: nmeum/cpod
func writeMarker(name string, latest time.Time) error {
	name, err := util.Escape(name)
	if err != nil {
		return err
	}

	path := filepath.Join(downloadDir, name, ".latest")
	if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
		return err
	}

	file, err := os.Create(path)
	if err != nil {
		return err
	}

	defer file.Close()
	if _, err := fmt.Fprintf(file, "%d\n", latest.Unix()); err != nil {
		return err
	}

	return nil
}