This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ewart4fun's profile picture

News program that updates using website

Started by ewart4fun, 06 December 2013 - 09:13 AM
ewart4fun #1
Posted 06 December 2013 - 10:13 AM
Hello all

I want to make a news program that reads text from my website. and prints it onto the screen.
my program prints the text to the screen like i want.
But i want it to wait for an update in the website and update the text after that.
If i compare the old text from the website and the new text from the website. it says the new text it has been looking for is different than the old one.
even though nothing changed
if i do
write(header2.readAll())

Then it says TABLE and after that some numbers and letters in stead of the text from the website.
Could anyone please help me with this and tell to me what I'm doing wrong in this code?

Spoiler

function timer(time)
repeat
  term.setCursorPos(1,15)
  print(time.." Seconds left before refresh")
  sleep(1)
  time = time - 1
until time < 1
end
while true do
term.clear()
term.setCursorPos(1, 1)
header = http.get("http://www.lua.net84.net/luabestanden/header")
text = http.get("http://www.lua.net84.net/luabestanden/text")
mon = peripheral.wrap("top")--
write(header.readAll())
write("\n\n")
write(text.readAll())
write("\n")
while true do
header2 = http.get("http://www.lua.net84.net/luabestanden/header")
  if header.readAll == header2.readAll then
   term.setCursorPos(1, 8)
   term.clearLine()
   print("same")
  else
   term.setCursorPos(1, 8)
   term.clearLine()
   print("different")
  end
end
--timer(10)
end
LBPHacker #2
Posted 06 December 2013 - 11:42 AM
  1. You cannot call .readAll of a HTTP handle twice (actually you can, but the second call will return nil, since you've already read everything - that's the point in .readAll)
  2. Comparing the .readAll methods of two different HTTP handles will of course evaluate false, since the two .readAll's aren't the same functions
  3. You should call the .close method of a HTTP handle if you no longer use it
Edited on 06 December 2013 - 11:41 AM
ewart4fun #3
Posted 06 December 2013 - 12:08 PM
oke thank you for answering :)/>
But is there a way to make this work?
ewart4fun #4
Posted 06 December 2013 - 12:28 PM
nevermind :)/>
i got it working. I made the header part on the website multiple times, now it works perfectly :D/>
Thank you for your help.

Spoiler

function timer(time)
repeat
term.setCursorPos(1,15)
print(time.." Seconds left before refresh")
sleep(1)
time = time - 1
until time < 1
end
while true do
term.clear()
term.setCursorPos(1, 1)
header = http.get("http://www.lua.net84.net/luabestanden/header")
headerread = header.readAll()
header2 = http.get("http://www.lua.net84.net/luabestanden/header2")
text = http.get("http://www.lua.net84.net/luabestanden/text")
textread = text.readAll()
mon = peripheral.wrap("top")–
write(headerread)
write("\n\n")
write(textread)
write("\n")
header2read = header2.readAll()
while true do
header3 = http.get("http://www.lua.net84.net/luabestanden/header3")
–write(header2.readAll())
–write("\n")
–write(header3.readAll())
header3read = header3.readAll()
if header2read == header3read then
term.setCursorPos(1, 8)
term.clearLine()
print("same")
else
term.setCursorPos(1, 8)
term.clearLine()
print("diffrent")
break
end
end
end
Edited on 06 December 2013 - 11:28 AM