bfchecker.bac

'------------------------------------------------------------------------------
' Orignal program by Tomaaz.
' Updated for new forum website avoiding CloudFare protection - PvE
' Updated: fixed bug when return from webserver contained multiple chunks - PvE
'-------------------------------------------------------------------------------
INCLUDE hug

OPTION COLLAPSE TRUE

SUB checking

    LOCAL pos, topics, posts, members, oldtopics, oldposts, oldmembers
    LOCAL data$, page$, txt$

    website$ = "basic-converter.proboards.com"
    port$ = "80"

    OPEN website$ & ":" & port$ FOR NETWORK AS net
    SEND "GET / HTTP/1.1\r\nHost: " & website$ & "\r\nUser-Agent: Mozilla/5.0\r\nAccept: text/html\r\nConnection: keep-alive\r\n\r\n" TO net

    WHILE WAIT(net, 1000)
        RECEIVE data$ FROM net
        page$ = page$ & data$
        IF LEN(data$) = 0 THEN BREAK
    WEND
    CLOSE NETWORK net

    page$ = CHOP$(REPLACE$(page$, " ", SPC$(1)))

    WHILE TRUE
        txt$ = INBETWEEN$(page$, "<tr><td>", "</td></tr>")
        page$ = OUTBETWEEN$(page$, "<tr><td>", "</td></tr>")

        IF NOT(LEN(txt$)) THEN
            BREAK
        ELIF ISTOKEN(txt$, "Total") THEN
            pos = ISTOKEN(txt$, "Threads:")
            IF pos THEN topics = VAL(TOKEN$(txt$, pos+1))

            pos = ISTOKEN(txt$, "Posts:")
            IF pos THEN posts = VAL(EXTRACT$(TOKEN$(txt$, pos+1), ","))

            pos = ISTOKEN(txt$, "Members:")
            IF pos THEN members = VAL(TOKEN$(txt$, pos+1))
        ENDIF
    WEND

    IF FILEEXISTS("baconforum.txt") THEN
        OPEN "baconforum.txt" FOR READING AS statistic
        READLN stat$ FROM statistic
        oldtopics = VAL(stat$)
        READLN stat$ FROM statistic
        oldposts = VAL(stat$)
        READLN stat$ FROM statistic
        oldmembers = VAL(stat$)
        CLOSE FILE statistic
    ENDIF

    TEXT (tottop, "Total topics: " & STR$(topics))
    TEXT (newtop, "New topics: " & STR$(topics - oldtopics))
    TEXT (totposts, "Total posts: " & STR$(posts))
    TEXT (newposts, "New posts: " & STR$(posts - oldposts))
    TEXT (totmembers, "Total members: " & STR$(members))
    TEXT (newmembers, "New members: " & STR$(members - oldmembers))

    SAVE STR$(topics) & NL$ & STR$(posts) & NL$ & STR$(members) & NL$ TO "baconforum.txt"

END SUB

win = WINDOW ("BFChecker", 200, 220)
che = BUTTON ("Check again", 100, 30)
tottop = MARK ("Total topics:", 180, 20)
newtop = MARK ("New topics:", 180, 20)
totposts = MARK ("Total posts:", 180, 20)
newposts = MARK ("New posts:", 180, 20)
totmembers = MARK ("Total members:", 180, 20)
newmembers = MARK ("New members: ", 180, 20)

ATTACH (win, newtop, 10, 10)
ATTACH (win, newposts, 10, 32)
ATTACH (win, newmembers, 10, 54)
ATTACH (win, tottop, 10, 90)
ATTACH (win, totposts, 10, 112)
ATTACH (win, totmembers, 10, 134)
ATTACH (win, che, 50, 180)

CALLBACK (che, checking)

TIMEOUT (1000, checking)

DISPLAY

Generated by GNU Enscript 1.6.5.90.