Skip to content

Instantly share code, notes, and snippets.

@cryptix
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptix/ffb6423b1e89edad36dc to your computer and use it in GitHub Desktop.
Save cryptix/ffb6423b1e89edad36dc to your computer and use it in GitHub Desktop.
watching openvpn announcment forum for changes and open the URL in your browser once there is a new post
package main
import (
"os"
"strconv"
"time"
"github.com/PuerkitoBio/goquery"
"github.com/cryptix/go/logging"
"github.com/pkg/browser"
)
var log = logging.Logger("openVPNcrit")
const (
annCnt = 16
annForumUrl = "https://forums.openvpn.net/announcements-f20.html"
secAnnUrl = "https://forums.openvpn.net/topic17625.html"
)
func main() {
lastR, lastV := 0, 0
for {
announcements := getAnnouncments()
if announcements != annCnt {
log.Noticef("# of Announcments changed!! %d", announcements)
browser.OpenURL(annForumUrl)
os.Exit(0)
}
r, v := getRepliesAndViews()
if r > lastR {
log.Noticef("# of Replies changed!! %d", r)
browser.OpenURL(secAnnUrl)
os.Exit(0)
}
lastR = r
log.Noticef("# of Views: %d (diff %d)", v, v-lastV)
lastV = v
time.Sleep(1 * time.Minute)
}
}
func getAnnouncments() int {
doc, err := goquery.NewDocument(annForumUrl)
logging.CheckFatal(err)
return doc.Find("#pagecontent table.tablebg tbody").Children().Length()
}
func getRepliesAndViews() (int, int) {
doc, err := goquery.NewDocument(annForumUrl)
logging.CheckFatal(err)
repItm := doc.Find("#pagecontent table.tablebg tbody tr:nth-child(3) td:nth-child(5)")
replies, err := strconv.Atoi(repItm.Text())
logging.CheckFatal(err)
viewsItm := doc.Find("#pagecontent table.tablebg tbody tr:nth-child(3) td:nth-child(6)")
views, err := strconv.Atoi(viewsItm.Text())
logging.CheckFatal(err)
return replies, views
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment