예제 #1
0
파일: aeropi.go 프로젝트: dhague/aeropi
func main() {

	log.Debug("Starting up...")

	dev, err := i2c.New(0x77, 1)
	if err != nil {
		log.Error("Error: %v", err)
	}
	bme, err := bme280.NewI2CDriver(dev)
	if err != nil {
		log.Error("Error: %v", err)
	}

	for {
		weather, err := bme.Readenv()

		density := atmosphere.AirDensity(atmosphere.TemperatureC(weather.Temp),
			atmosphere.Pressure(weather.Press*100),
			atmosphere.RelativeHumidity(weather.Hum))
		if err != nil {
			log.Error("Error: %v", err)
		} else {
			log.Debug(fmt.Sprintf("Temperature (degC) %2.2f, pressure (mbar) %4.2f, humidity %2.2f, Density %2.3f kg/m3, CorrFact %1.4f",
				weather.Temp, weather.Press, weather.Hum, float64(density), float64(density*0.8)))
		}

		<-time.After(5 * time.Second)
	}
}
예제 #2
0
func Feed(w http.ResponseWriter, r *http.Request) {
	log.Debug("crawler passed by", "user-agent", r.Header.Get("User-Agent"))
	files := FileList()
	c := gopod.ChannelFactory("Poddy!", common.Self, "Personal poddy feed...", fmt.Sprintf("%s/static/images/poddy.png", common.Self))
	c.SetPubDate(time.Now().UTC())
	c.SetiTunesExplicit("No")

	for _, file := range files {
		link := fmt.Sprintf("%s/download/%s", "http://poddy.lommers.org", file.Name)
		i := &gopod.Item{
			Title:         file.Name,
			TunesSubtitle: file.Name,
			Link:          link,
			Description:   file.Name,
			Guid:          link,
			Creator:       "Rogier",
		}

		i.SetEnclosure(link, "1", file.Filetype)
		i.SetPubDate(time.Now().Unix())
		c.AddItem(i)
	}
	feed := c.Publish()
	w.Write([]byte(feed))

}
예제 #3
0
파일: main.go 프로젝트: Taik/zing-mp3
func (a *albumJob) startDownloader() {
	defer a.downloadSync.Done()

	for item := range a.downloadQueue {
		buf := a.bufferPool.Get()

		log.Debug("Processing album item",
			"artist", item.Artist,
			"title", item.Title,
			"url", item.ItemURL,
		)

		err := downloadURL(buf, item.DownloadURL)
		if err != nil {
			log.Error("Unable to download item",
				"download_url", item.DownloadURL,
				"error", err,
			)
			return
		}
		a.zipQueue <- zipFile{
			Filename: item.Name(),
			Buffer:   buf,
		}
		log.Info("Processed album item",
			"download_url", item.DownloadURL,
			"filename", item.Name(),
		)
	}
}
예제 #4
0
파일: file.go 프로젝트: rogierlommers/poddy
func moveMP3toStorageDirectory(watchdir, storage string) {
	files, err := ioutil.ReadDir(watchdir)
	if err != nil {
		log.Error("scan error", "error", err)
		return
	}

	for _, file := range files {
		if !file.IsDir() {
			if strings.HasSuffix(file.Name(), "mp3") {
				source := filepath.Join(watchdir, file.Name())
				target := filepath.Join(storage, file.Name())

				// first copy file
				log.Info("about to copy file", "source", source, "target", target)
				err := copyFileContents(source, target)
				if err != nil {
					log.Error("copy error", "error", err)
					return
				}

				// then delete original file
				err = os.Remove(source)
				if err != nil {
					log.Error("error deleting source file", "error", err)
				}
			}
			log.Debug("only process mp3 files")
		}
	}
}
예제 #5
0
파일: main.go 프로젝트: bradobro/corazones
func main() {
	key := os.Getenv("OPSGENIE_KEY")
	config := heartbeats.LoadConfiguration()
	// sendHeartbeat("solomon", key)
	if config.Debug {
		log.Debug("Running in debug mode.", "configuration", config)
	} else {
		heartbeats.Beat("hezekiah", key, time.Minute)
	}
}
예제 #6
0
파일: main.go 프로젝트: Taik/zing-mp3
func downloadURL(buf *bytes.Buffer, url string) error {
	log.Debug("Downloading item", "download_url", url)
	response, err := http.Get(url)
	if err != nil {
		log.Error("Unable to request album item", "download_url", url)
		return err
	}
	defer response.Body.Close()
	io.Copy(buf, response.Body)

	return nil
}
예제 #7
0
// LoadConfiguration loads configuration from files, environment,
// and/or cluster storage
func LoadConfiguration() *Config {
	result := new(Config)
	result.Debug = true
	setEnvironment()

	// setDefaults()
	loadConfig(result)
	// postProcess()

	log.Debug("Loading config.")
	return result
}
예제 #8
0
파일: main.go 프로젝트: Taik/zing-mp3
func (a *albumJob) startZipper() {
	defer a.zipSync.Done()

	zipBuffer := zip.NewWriter(a.zipWriter)
	defer zipBuffer.Close()

	for file := range a.zipQueue {
		filename := file.Filename
		log.Debug("Creating new item in archive",
			"filename", filename,
		)

		f, err := zipBuffer.Create(filename)
		if err != nil {
			log.Error("Unable to create new item in archive",
				"filename", filename,
			)
			return
		}

		log.Debug("Copying buffer into zip file",
			"filename", filename,
		)

		_, err = io.Copy(f, file.Buffer)
		if err != nil {
			log.Error("Unable to copy buffer into zip file",
				"filename", filename,
			)
			return
		}
		a.bufferPool.Put(file.Buffer)
		zipBuffer.Flush()
	}
	log.Debug("Archive completed")
}
예제 #9
0
파일: file.go 프로젝트: rogierlommers/poddy
// FileList returns slice of UploadedFiles
func FileList() []UploadFile {
	items := []UploadFile{}
	log.Debug("opening dir", "dirname", common.Storage)

	list, err := ioutil.ReadDir(common.Storage)
	if err != nil {
		log.Error("storage error", "error", err)
	}

	for _, file := range list {
		newFile := UploadFile{}
		if file.Mode().IsRegular() {
			newFile.Name = file.Name()
			newFile.Size = file.Size()
		}
		items = append(items, newFile)
	}
	return items
}
예제 #10
0
파일: main.go 프로젝트: koolshare/demux
func main() {
	rootLog.Info("Started")

	// For each registered protocol, we add the corresponding flags for its
	// destination.
	protocolFlags := make(map[string]*string)
	for name, _ := range protocols {
		protocolFlags[name] = flag.String(name+"-destination", "",
			"destination to forward "+name+" traffic to")
	}

	// Parse all flags.
	flag.Parse()

	// First off, handle flags that cause us to exit instead of actually listening
	checkExitFlags()
	validateFlags()

	// Find out what we've got enabled
	enabledProtocols := []Protocol{}
	protoDestinations := make(map[string]*net.TCPAddr)
	descString := ""
	for name, flag := range protocolFlags {
		if len(*flag) > 0 {
			// Validate that we can parse this address
			addr, err := net.ResolveTCPAddr("tcp", *flag)
			if err != nil {
				log.Crit("Invalid TCP address",
					"addr", *flag,
					"err", err,
				)
				return
			}

			protoDestinations[name] = addr
			enabledProtocols = append(enabledProtocols, protocols[name])
			descString += name + ","
		}
	}

	if len(enabledProtocols) == 0 {
		rootLog.Crit("No protocols were enabled")
		return
	}

	log.Debug("Enabled protocols: " + descString[0:len(descString)-1])

	// Start listening
	addr := fmt.Sprintf("%s:%d", flagListenHost, flagListenPort)
	l, err := net.Listen("tcp", addr)
	if err != nil {
		rootLog.Crit("Could not open listener", "err", err)
		return
	}
	defer l.Close()

	rootLog.Info("Started listening", "addr", addr)
	for {
		conn, err := l.Accept()
		if err != nil {
			rootLog.Error("Error accepting connection", "err", err)
			continue
		}

		p := NewProxy(conn, rootLog)
		p.EnabledProtocols = enabledProtocols
		p.ProtoDestinations = protoDestinations
		go p.Start()
	}
}