@name Cenn's Weather App
@inputs  E:wirelink
@outputs OwnerRequest
@persist Data:string OwnerRequest TOWN:string T:number Weather:string
@trigger 

 if(first()) {
    E:egpClear()
    E:egpBox(1,vec2(0,0),vec2(800,800))
    E:egpPos(1,vec2(250,250))
    E:egpColor(1,vec4(40,40,150,255))
    

      E:egpText(2,"Cenn's Magical Real Weather Box",vec2(20,55))
    E:egpFont(2,"Arial")
    E:egpSize(2,35)
    
        E:egpText(3,"Cenn's Magical Real Weather Box",vec2(15,50))
    E:egpFont(3,"Arial")
    E:egpSize(3,35)
    
    E:egpColor(2,vec4(0,0,0,255))
    
      E:egpRoundedBox(5,vec2(130,210),vec2(200,200))
    E:egpColor(5,vec4(0,0,0,100))
    
     E:egpBox(4,vec2(120,200),vec2(200,200))
    E:egpColor(4,vec4(100,100,255,255))
    
           E:egpRoundedBox(6,vec2(430,410),vec2(200,200))
    E:egpColor(6,vec4(0,0,0,100))
    
     E:egpBox(7,vec2(400,400),vec2(200,200))
    E:egpColor(7,vec4(100,100,255,255))
    
    
    
    E:egpText(8,"TOWN",vec2(80,100))
    E:egpFont(8,"Arial")
    E:egpSize(8,35)
    
     E:egpText(9,"TEMP",vec2(80,160))
    E:egpFont(9,"Arial")
    E:egpSize(9,35)
    
       E:egpText(10,"WEATHERTEXT",vec2(310,320))
    E:egpFont(10,"Arial")
    E:egpSize(10,30)
    
    
    
        runOnHTTP(1)
        runOnChat(1)
        OwnerRequest=0
        TOWN = "Hoisington"
        T = 0
    }


 if(httpCanRequest()) {
   # print("Stepone?")
 ##   print(OwnerRequest)
    if(OwnerRequest ==1){
        print("requesting! " + TOWN)
        httpRequest("https://api.wunderground.com/api/e5ffb0d8c15a20a6/geolookup/conditions/q/IA/" + TOWN + ".json")
OwnerRequest = 0
}} else {
timer("Cant",3000)
 ## print("API CANNOT BE REECHED </3")
    }
if(clk("Cant")){
#print("API CANNOT BE REECHED </3")
}
    
if(httpClk()){
    stoptimer("Cant")
    OwnerRequest = 0
   ## print(OwnerRequest)
    Data = httpData()
}

if(Data:find("city")){
    if(changed(Data)){
    if(OwnerRequest==0){
    City1 = Data:explode("city"):string(2):left(15)
    Weather1 = Data:explode("weather"):string(4):left(13)
    Temp1 = Data:explode("temperature_string"):string(2):left(20)
   City2 = City1:replace(":","")
City3 = City2:replace("\"","")
City4 = City3:replace(",","")

 Temp2 = Temp1:replace(":","")
Temp3 = Temp2:replace("\"","")
Temp4 = Temp3:replace(",","")

 Weather2 = Weather1:replace(":","")
Weather3 = Weather2:replace("\"","")
Weather4 = Weather3:replace(",","")
Temp = Temp4
City = City4
Weather = Weather4
    print(City)
    print(Temp)
    print(Weather)
        E:egpText(8,City,vec2(100,100))
        E:egpAlign(8,1)
           E:egpText(9,Temp,vec2(125,160))
         E:egpAlign(9,1)
          
       E:egpText(10,Weather,vec2(360,320))
     E:egpAlign(10,1)
}}}

 if(owner():lastSaid():explode("!w "):string(1)==""){ 
    if(changed(owner():lastSaid())){
    if(OwnerRequest==0){
     hideChat(1)   
     TOWN2 = owner():lastSaid():explode("!w "):string(2)
    T++
   # TOWN1 = owner():lastSaid():explode("!w"):string(2):left(20)
  #  TOWN2 = TOWN1:right(-3):replace(" ","")
    TOWN3 = TOWN2:replace(" ", "%20")
    TOWN = TOWN3
   OwnerRequest = 1
print(TOWN + " Request sent in chat!")
print(Weather)
 OwnerRequest = 1
#print(OwnerRequest)
}}}

if(Weather=="Clear"){
    print("Test!")
 E:egpBox(20,vec2(0,0),vec2(200,200))
E:egpPos(20,vec2(150,150))   
}
