コード例 #1
0
ファイル: ufc.go プロジェクト: Integralist/ufc-event-notifier
func check() {
	doc, err := goquery.NewDocument("http://www.ufc.com/schedule/event")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// My filtering of content is obviously very fragile and error prone
	// It'll likely need changing every time UFC change the structure of their page
	doc.Find("#event_content > div").Each(func(i int, s *goquery.Selection) {
		event := s.Find(".event-title").Text()

		if invalid(event) {
			return
		}

		// Stop after the first item
		// We could try using `.First()` but we have no way with CSS to determine valid item
		if i > 2 {
			return
		}

		extractedDate := strings.TrimSpace(
			s.Find(".event-info .date").Text(),
		)

		date := strings.Join(
			[]string{
				extractedDate,
				strconv.Itoa(
					time.Now().AddDate(verifyYear(extractedDate), 0, 0).Year(),
				),
			},
			" ",
		)

		t, _ := time.Parse(standardDate, date)
		daysAway := daysDiff(t, time.Now())

		switch {
		case withinAWeek(daysAway):
			mack.Say(fmt.Sprintf("The UFC Event %s is coming up in a week", event))
			mack.Notify(fmt.Sprintf("%s (%d days away)", date, daysAway), "UFC Event", event, "Ping")
		case withinAFewDays(daysAway):
			mack.Say(fmt.Sprintf("The UFC Event %s is coming up in a few days", event))
			mack.Notify(fmt.Sprintf("%s (%d days away)", date, daysAway), "UFC Event", event, "Ping")
		case startsToday(daysAway):
			mack.Say(fmt.Sprintf("The UFC Event %s is TODAY!", event))
			mack.Notify(fmt.Sprintf("%s (%d days away)", date, daysAway), "UFC Event", event, "Ping")
		}
	})
}
コード例 #2
0
ファイル: main.go プロジェクト: Coccodrillo/gingin
func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {
	err := builder.Build()
	if err != nil {
		buildError = err
		logger.Println("ERROR! Build failed.")
		fmt.Println(builder.Errors())
	} else {
		// print success only if there were errors before, otherwise tell when rebuilt
		var notificationMessage string
		if buildError != nil {
			notificationMessage = "Build Successful"
			logger.Println(notificationMessage)
		} else {
			var curDir1 string
			curDir, _ := os.Getwd()
			segments := strings.Split(curDir, "/")
			if len(segments) > 0 {
				curDir1 = segments[len(segments)-1]
			}
			notificationMessage = fmt.Sprintf("%v - Rebuilt at %v \n", curDir1, time.Now().Format("15:04:05.999999"))
			logger.Printf(notificationMessage)
		}
		fmt.Println(notificationsEnabled)
		if notificationMessage != "" && notificationsEnabled {
			mack.Notify(notificationMessage)
		}
		buildError = nil
		if immediate {
			runner.Run()
		}
	}

	time.Sleep(100 * time.Millisecond)
}
コード例 #3
0
func main() {
	// do stuff
	//mack.Notify("Complete")
	for {
		resp, err := http.Get("http://synd.cricbuzz.com/j2me/1.0/livematches.xml")
		if err != nil {
			panic("Failed")
		}
		str, _ := ioutil.ReadAll(resp.Body)
		defer resp.Body.Close()
		//decoder := xml.NewEncoder(resp.Body)
		var v Root
		err = xml.Unmarshal(str, &v)
		if err != nil {
			fmt.Println("Error is : ", err)
		}
		fmt.Println("%+v", v)
		for key, value := range v.Matches {
			if key == 0 {
				title := fmt.Sprintf("AUS : %s/%s  ", value.Mscr.Team.Inngs.R, value.Mscr.Team.Inngs.Wickets)
				subTitle := fmt.Sprint("Overs : ", value.Mscr.Team.Inngs.Overs)
				fmt.Println("title is : ", title)
				mack.Notify(subTitle, title)
			}
		}
		time.Sleep(1 * time.Minute)
	}
}
コード例 #4
0
ファイル: minion.go プロジェクト: Geekfish/go-minion
func main() {
	response, err := mack.Dialog("Enter a count down", "Count down", "10")
	if err != nil {
		panic(err)
	}
	if response.Clicked == "Cancel" {
		return
	} else {
		mack.Notify("Will notify every " + response.Text + " seconds")
		interval, _ := strconv.Atoi(response.Text)
		sleepTime := time.Duration(interval) * time.Second
		for {
			time.Sleep(sleepTime)
			mack.Notify("Posture check? Looking good!")
		}
	}
}
コード例 #5
0
func main() {
	var database DataBase
	var notify *notificator.Notificator
	notify = notificator.New(notificator.Options{
		DefaultIcon: "icon/default.png",
		AppName:     "Youtube",
	})

	database.session, _ = mgo.Dial("localhost:27017")
	defer database.session.Close()
	fmt.Println("session connected to mongodb")
	c := database.session.DB("youtube").C("toDownload")
	var R *Result
	//fmt.Println(*R)
	iter := c.Find(nil).Sort("$natural").Tail(time.Second * 5)
	for {
		for iter.Next(&R) {
			Res := R
			fmt.Println("Added result : " + Res.Url)
			notify.Push("Youtube Video", Res.Url, "", notificator.UR_NORMAL)
			mack.Notify(Res.Url, "Youtube")
			if !R.isDownloaded(&database) {
				go func(Res *Result) {
					err := R.download()
					if err == nil {
						Res.updateDB(&database)
						fmt.Println("waiting for : " + Res.Url)
						if err != nil {
							fmt.Println("Error while downloading video : " + Res.Url)
							fmt.Println(err)
						}
					}
				}(Res)
			} else {
				log.Printf("Video is already downloaded ", R.Url)
			}
		}
	}
}