Пример #1
0
func New(db *database.DB,
	mailer mailer.Mailer,
	log *logrus.Logger,
	cfg *config.Config) *Server {

	secureCookieKey, _ := base64.StdEncoding.DecodeString(cfg.SecureCookieKey)

	cookie := securecookie.New(
		[]byte(cfg.SecretKey),
		secureCookieKey,
	)

	renderOptions := render.Options{
		IsDevelopment: cfg.IsDev(),
	}

	renderer := render.New(renderOptions)

	feedparser := feedparser.New()

	return &Server{
		DB:         db,
		Config:     cfg,
		Log:        log,
		Render:     renderer,
		Cookie:     cookie,
		Feedparser: feedparser,
		Mailer:     mailer,
	}
}
Пример #2
0
// Fetch retrieves latest podcasts
func Fetch(cfg *config.Config) {

	db := database.MustConnect(cfg)
	defer db.Close()

	log := logrus.New()

	log.Formatter = &logrus.TextFormatter{
		FullTimestamp: true,
		ForceColors:   true,
	}

	f := feedparser.New(db, log)
	if err := f.FetchAll(); err != nil {
		panic(err)
	}

}
Пример #3
0
// Fetch retrieves latest podcasts
func Fetch(cfg *config.Config) {

	db := database.MustConnect(cfg)
	defer db.Close()

	log := configureLogger()
	log.Info("fetching...")

	channels, err := db.Channels.SelectAll()

	if err != nil {
		panic(err)
	}

	f := feedparser.New()

	for _, channel := range channels {

		log.Info("Channel:" + channel.Title)

		if err := f.Fetch(&channel); err != nil {
			log.Error(err)
			continue
		}

		if err := db.Channels.Create(&channel); err != nil {
			log.Error(err)
			continue
		}

		for _, p := range channel.Podcasts {
			p.ChannelID = channel.ID
			if err := db.Podcasts.Create(p); err != nil {
				log.Error(err)
				continue
			}
		}

	}

}