コード例 #1
0
ファイル: update.go プロジェクト: jcswart/godock
// Program launched. Create and activate applet.
//
func main() {
	app := Update()

	log.SetPrefix(term.Yellow("[" + app.AppletName + "] "))
	log.Println(term.Green("Applet started"))
	defer log.Println(term.Yellow("Applet stopped"))

	// Start main loop and wait for events. Until the End signal is received from the dock.
	ticker, restart := app.poller.NewTicker()
	for { // Main loop, waiting for events.
		select {
		case <-app.Close: // That's all folks.
			return

		// not triggered yet.
		case <-restart: // Want to recheck now ?
			log.Println(term.Yellow("timer restart"))
			ticker, restart = app.poller.NewTicker()

		case <-ticker.C: // It's time to work !
			//~ log.Println(term.Yellow("timer"))
			app.poller.Check()
		}
	}
}
コード例 #2
0
ファイル: opensubs.go プロジェクト: sqp/opensubs
func (q *Query) Get(n int) (subByRef, subByRef) {
	var dl []string
	needed := make(subIndex)

	// Parsing list byhash. Need one file
	for _, bylang := range q.byhash { // For each movie
		for _, list := range bylang { // For each lang
			if len(list) > 1 {
				warn("multiple ref for hash matched")
			}
			sort.Sort(byDownloads{list})
			sub := list[0]
			needed[sub.IDSubtitleFile] = sub
			dl = append(dl, sub.IDSubtitleFile)
		}
	}

	//~ printSubByRef("Matched by Hash", q.byhash)

	// Parsing list byimdb to get multiple files.
	for imdb, bylang := range q.byimdb { // For each movie
		for _, list := range bylang { // For each lang

			sort.Sort(byDownloads{list})
			count := 0

			log.Println(term.Magenta("Movie found"), "  imdb:", imdb) //strconv.Itoa(imdb))

			for _, sub := range list { // each sub
				if n == -1 || count < n { // Unlimited or within limit: add to list.
					needed[sub.IDSubtitleFile] = sub
					dl = append(dl, sub.IDSubtitleFile)
					log.Println(term.Green(sub.SubLanguageID), sub.SubAddDate[:10], term.Yellow(sub.SubDownloadsCnt), sub.UserNickName, term.Bracket(sub.UserRank))

					//~ break

				} else {
					log.Println(term.Magenta(sub.SubLanguageID), sub.SubAddDate, sub.UserNickName, term.Bracket(sub.UserRank), term.Yellow(sub.SubDownloadsCnt))
				}
				count++
			}
		}
	}
	return q.download(dl, needed)
}