@name HTTPTEST PATATO
@inputs S:wirelink
@outputs 
@persist 
@trigger all
runOnHTTP(1)

if (first()){
    httpRequest("http://www.aperturescience.com/glados@home/")
    S:egpClear()
}

if(first()){
    ID = "potato_count"
    Potatos = httpData():explode("<div id="+ toChar(34) + ID + toChar(34) + ">")
    Potato = Potatos[2, string]
    Potato = Potato:explode("<")[1, string]
    Potato = Potato:trim()
    
    ID2 = ""
    Times = httpData():explode("<div id="+ toChar(34) + ID2 + toChar(34) + ">")
    Time = Times[2, string]
    Time = Time:explode("<")[1, string]
    Time = Time:trim()
    
    S:egpText(1, "Potato count: " + Potato, vec2(0,0))  
    S:egpText(2, "Estimated Time: " + Time, vec2(0,20))  
    S:egpText(3, "Current % ", vec2(0,40))  
    S:egpColor(1,vec(1,1,1)) 
    S:egpColor(2,vec(1,1,1)) 
    S:egpColor(3,vec(1,1,1))
}

timer("ref",10000)
if(clk("ref")){    

    ID = "potato_count"
    Potatos = httpData():explode("<div id="+ toChar(34) + ID + toChar(34) + ">")
    Potato = Potatos[2, string]
    Potato = Potato:explode("<")[1, string]
    Potato = Potato:trim()
    
    S:egpText(1, "Potato count: " + Potato, vec2(0,0))
}

