Beispiel #1
0
func main() {

	setup()

	// Logging
	if term {
		log.Printf("logging to terminal \n")
	} else {
		log.Printf("logging to rssnest.log \n")
		f, err := os.OpenFile("rssnest.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			log.Fatalf("error opening file: %v", err)
		}
		defer f.Close()
		log.SetOutput(f)
	}

	store := new(FileStore)
	source := new(HttpSource)
	feeds.StoreNewContent(store, source)

	target := new(FtpTarget)
	short := new(GoogleShort)
	conf := config.GetConfig()
	prices := feeds.GetPrices()
	Propagate(store, target, prices, short, conf)
}
// Maybe this just take a harvester which contains the source and the store and the processing logic
func StoreNewContent(store Store, source Source) {
	conf := config.GetConfig()
	var cs = loadRSSList(conf)
	var total = len(cs.Feeds)
	log.Printf("%v RSS feeds found \n", total)
	for i := 0; i < total; i++ {
		item := cs.Feeds[i]
		name := item.Name
		log.Printf("\n")
		log.Printf("\n=================================================================\n")
		log.Printf("[%v/%v] %s (%s) \n", i, total, name, item.Date)
		Leach(item, store, source, 1)
	}
}
Beispiel #3
0
func (s FtpTarget) Send(newItems []feeds.RssResult, prices []feeds.GoldMoney) {
	conf := config.GetConfig()
	var perm os.FileMode = 0777
	var err error
	var ftp *goftp.FTP

	log.Printf("...saving newData (%v) file to ftp to %v\n", len(newItems), conf.Propagate.Ftp.Url)
	var newData = []byte("var data = \n")
	jsave, _ := json.Marshal(newItems)
	for _, e := range jsave {
		newData = append(newData, e)
	}
	ioutil.WriteFile(conf.General.DataDir+"newData.json", newData, perm)
	var file *os.File
	if file, err = os.Open(conf.General.DataDir + "newData.json"); err != nil {
		panic(err)
	}
	defer file.Close()
	addr := fmt.Sprintf("%v:%v", conf.Propagate.Ftp.Url, conf.Propagate.Ftp.Port)
	if ftp, err = goftp.Connect(addr); err != nil {
		panic(err)
	}
	defer ftp.Close()
	if err = ftp.Login(conf.Propagate.Ftp.Usr, conf.Propagate.Ftp.Pw); err != nil {
		panic(err)
	}
	// This is failing for some reason????
	// One line curl seems to do it....    curl -T newData.json ftp://blarblar.net --user fred:donttell
	//	if err := ftp.Stor("newData.json", file); err != nil {
	//		panic(err)
	//	}

	log.Printf("saving prices (%v) file to ftp to webserver\n\n\n", len(prices))
	var data3 = []byte("var prices = \n")
	jsave2, _ := json.Marshal(prices)
	for _, e := range jsave2 {
		data3 = append(data3, e)
	}
	ioutil.WriteFile(conf.General.DataDir+"prices.json", data3, perm)
	var pricesFile *os.File
	if pricesFile, err = os.Open(conf.General.DataDir + "prices.json"); err != nil {
		panic(err)
	}
	defer pricesFile.Close()
	// This is failing for some reason????
	// One line curl seems to do it....    curl -T price.json ftp://blarblar.net --user fred:donttell
	//	if err := ftp.Stor("prices.json", pricesFile); err != nil {
	//		panic(err)
	//	}
}
Beispiel #4
0
func (s FtpTarget) Message(util Shortener, msg string, url string) {
	conf := config.GetConfig()
	anaconda.SetConsumerKey(conf.Propagate.Tweet.ConsumerKey)
	anaconda.SetConsumerSecret(conf.Propagate.Tweet.ConsumerSecret)
	api := anaconda.NewTwitterApi(conf.Propagate.Tweet.AccessTokenKey, conf.Propagate.Tweet.AccessTokenSecret)
	short := util.Shorten(url, conf.Propagate.Apikey)
	link := url
	if short.Err == nil {
		log.Printf("%v shortened to %v", url, short.Id)
		link = short.Id
	} else {
		log.Printf("Failed shortening")
		log.Printf("%v", short.Err)
	}

	full := link + " " + msg
	if len(full) > 140 {
		full = full[0:137] + "..."
	}
	log.Printf("Full message to tweet is '%v'\n", full)
	api.PostTweet(full, nil) // "https://twitter.com/rssnest")
}