Example #1
0
//check saved data and run browser if needed
func checkSavedTeachers() {
	var openFlg bool
	ths := th.GetsavedTeachers()
	//open browser
	if len(ths) != 0 {
		//save status
		if redisFlg {
			openFlg = saveStatusLog(rd.Get(), ths)
		} else {
			openFlg = saveStatusLog(tt.Get(), ths)
		}
		fmt.Println(openFlg)
		if openFlg {
			if mailFlg {
				// for sending mail
				ml.Send(ths)
			} else {
				//Browser Mode
				openBrowser(ths)

				//emit a sound
				_ = exec.Command("say", "Found").Start()
			}
		}
	}
}
Example #2
0
func clear() {
	if redisFlg {
		clearData(rd.Get())
	} else {
		clearData(tt.Get())
	}
	//deleteTxt(txtPath)
	//deleteRedisKey()

	*jsPath = ""
}
Example #3
0
//2.execMain() return value is whether executed scraping or not.
func execMain(testFlg uint8) bool {
	lg.Info("getting teacher's information")

	var si *th.SiteInfo
	//m = new(sync.Mutex)

	if *jsPath != "" {
		//json
		si = th.LoadJSONFile(*jsPath)
	} else {
		//use build teacher data
		si = th.GetDefinedData()
	}

	for {
		//reset
		th.InitSavedTeachers()

		//scraping
		handleTeachers(si)

		//save
		checkSavedTeachers()

		//TODO:when integration test, send channel
		//execuite only once on heroku

		if herokuFlg == "1" {
			if rd.Get() != nil {
				rd.Get().RD.Close()
			}
			return true
		} else if testFlg == 1 {

			return true
		}

		time.Sleep(time.Duration(*interval) * time.Second)
	}
}
Example #4
0
func teardown() {
	rd.Get().RD.Close()
}