Read/use website raw text for cool stuff (Idea)
Started by TyDoesMC, Nov 07 2015 01:54 AM
14 replies to this topic
#1
Posted 07 November 2015 - 01:56 AM
Hello, I was wondering if one of you could give me a snippet of reading a websites raw text for a boolean or function. Like I have a page on my site with true or false that way I can make my turtle or computer work over the internet. I know its possible but have lost interest in computercraft and forgot alot and never knew anything about https
this code doesn't work its for better understanding of my question
website = http://www.example.com/cc
if website == "true" then
print("It works!")
this code doesn't work its for better understanding of my question
website = http://www.example.com/cc
if website == "true" then
print("It works!")
#3
Posted 07 November 2015 - 07:44 PM
Thankyou. this is a good way for an auto updater!
#4
Posted 07 November 2015 - 10:41 PM
It always say update found my code is very basic.
version = http.get("http://pastebin.com/raw.php?i=9nXEnf7x")
currentVersion = "1.0.0"
if currentVersion ~= version then
print("Update found!")
else
print("No update")
version = http.get("http://pastebin.com/raw.php?i=9nXEnf7x")
currentVersion = "1.0.0"
if currentVersion ~= version then
print("Update found!")
else
print("No update")
#5
Posted 07 November 2015 - 11:03 PM
http.get() returns a web handle. You can read data from this handle, but the handle does not directly represent the data itself. Take another look at what Yami's doing in his example, at this article, and at this section.
Edited by Bomb Bloke, 07 November 2015 - 11:05 PM.
#6
Posted 07 November 2015 - 11:13 PM
Ok I updated it.
still doesn't work.
I added
version_read = version.readAll()
then I use version_read in place but still no avail.
version = http.get("http://pastebin.com/raw.php?i=9nXEnf7x")
currentVersion = "1.0.0"
version_read = version.readAll()
if currentVersion ~= version_read then
print("Update found!")
else
print("No update")
still doesn't work.
I added
version_read = version.readAll()
then I use version_read in place but still no avail.
version = http.get("http://pastebin.com/raw.php?i=9nXEnf7x")
currentVersion = "1.0.0"
version_read = version.readAll()
if currentVersion ~= version_read then
print("Update found!")
else
print("No update")
#7
Posted 07 November 2015 - 11:18 PM
Try this:
What does this print?
local h, version = http.get( "http://pastebin.com/raw.php?i=9nXEnf7x" )
if h then
version = h.readAll()
print( version )
if version ~= "1.0.0" then
print( "Update Found!" )
else
print( "No Update Found!" )
end
else
print( "Couldn't connect to pastebin!" )
end
What does this print?
#8
Posted 07 November 2015 - 11:59 PM
Ok it works ty
#9
Posted 08 November 2015 - 02:59 AM
Why won't this work?
It updates no matter what.
It updates no matter what.
--[[ Login screen ]]--
username = "Admin"
Access = "Login"
password = "password"
currentVersion = "1.3.2"
updateAvailable = "false"
autoUpdate = "true"
os.pullEvent = os.pullEventRaw
--[[ functions ]]--
function startscreen(print)
term.clear()
term.setCursorPos(1,1)
print("+========+")
print("|Craft OS|")
print("+========+")
print("")
print("+=======================+")
print("|Username: |")
print("+=======================+")
print("")
print("+=======================+")
print("|Password: |")
print("+=======================+")
print("")
print("Access: "..Access.."")
end
function login()
term.setCursorPos(12,6)
unbox = read()
if unbox == "update" then
autoupdate()
elseif unbox ~= username then
term.setCursorPos(9,13)
print("Incorrect username!")
sleep(2)
shell.run("startup")
else
term.setCursorPos(1,13)
term.setCursorPos(1,13)
term.setCursorPos(12,10)
pwbox = read("*")
if pwbox == password then
term.setCursorPos(1,13)
print("")
term.setCursorPos(1,13)
Access = "Granted!"
print("Access: "..Access.."")
sleep(3)
term.clear()
term.setCursorPos(1,1)
else
os.reboot()
end
end
end
function updateCheck()
term.clear()
term.setCursorPos(1,1)
print("+--------------------------+")
print("|Checking for updates... |")
print("+--------------------------+")
print("+--------------------------+")
print("| |")
print("+--------------------------+")
term.setCursorPos(2,5)
textutils.slowPrint("//////////////////////////", 8)
term.clear()
term.setCursorPos(1,1)
h, version = http.get( "http://pastebin.com/raw.php?i=9nXEnf7x" )
if h then
version = h.readAll()
if version ~= currentVersion then
print("+--------------------------+")
print("|Update found! |")
print("+--------------------------+")
print("+--------------------------+")
print("|Version: |")
print("+--------------------------+")
print("+--------------------------+")
print("|Downloading... |")
print("+--------------------------+")
term.setCursorPos(11,5)
print(version)
sleep(3)
shell.run("pastebin run JuYtAwrk")
else
print("+--------------------------+")
print("|Current update owned! |")
print("+--------------------------+")
end
else
print( "Couldn't connect to pastebin!" )
end
end
updateCheck()
startscreen(print)
login()
#10
Posted 08 November 2015 - 12:42 PM
A quick shot-in-the-dark guess, but what happens if you switch to h.readLine() instead of h.readAll()? I suspect you're pulling in a linebreak you don't want.
It'd also be a good idea to call h.close() after your read.
It'd also be a good idea to call h.close() after your read.
#11
Posted 08 November 2015 - 07:22 PM
Bomb Bloke, on 08 November 2015 - 12:42 PM, said:
A quick shot-in-the-dark guess, but what happens if you switch to h.readLine() instead of h.readAll()? I suspect you're pulling in a linebreak you don't want.
It'd also be a good idea to call h.close() after your read.
It'd also be a good idea to call h.close() after your read.
You actually have to close http handles?
#12
Posted 08 November 2015 - 11:47 PM
They time out sooner or later if you don't, but there's no point in having them consume resources for longer than they have to.
#13
Posted 09 November 2015 - 12:54 AM
I get this error with this code


--[[ Login screen ]]--
username = "Admin"
Access = "Login"
password = "password"
currentVersion = "1.3.2"
updateAvailable = "false"
autoUpdate = "true"
os.pullEvent = os.pullEventRaw
--[[ functions ]]--
function startscreen(print)
term.clear()
term.setCursorPos(1,1)
print("+========+")
print("|Craft OS|")
print("+========+")
print("")
print("+=======================+")
print("|Username: |")
print("+=======================+")
print("")
print("+=======================+")
print("|Password: |")
print("+=======================+")
print("")
print("Access: "..Access.."")
end
function login()
term.setCursorPos(12,6)
unbox = read()
if unbox == "update" then
autoupdate()
elseif unbox ~= username then
term.setCursorPos(9,13)
print("Incorrect username!")
sleep(2)
shell.run("startup")
else
term.setCursorPos(1,13)
term.setCursorPos(1,13)
term.setCursorPos(12,10)
pwbox = read("*")
if pwbox == password then
term.setCursorPos(1,13)
print("")
term.setCursorPos(1,13)
Access = "Granted!"
print("Access: "..Access.."")
sleep(3)
term.clear()
term.setCursorPos(1,1)
else
os.reboot()
end
end
end
function updateCheck()
term.clear()
term.setCursorPos(1,1)
print("+--------------------------+")
print("|Checking for updates... |")
print("+--------------------------+")
print("+--------------------------+")
print("| |")
print("+--------------------------+")
term.setCursorPos(2,5)
textutils.slowPrint("//////////////////////////", 8)
term.clear()
term.setCursorPos(1,1)
h, version = http.get( "http://pastebin.com/raw.php?i=9nXEnf7x" )
if h then
version = h.readLine()
h.close()
if version ~= currentVersion then
print("+--------------------------+")
print("|Update found! |")
print("+--------------------------+")
print("+--------------------------+")
print("|Version: |")
print("+--------------------------+")
print("+--------------------------+")
print("|Downloading... |")
print("+--------------------------+")
term.setCursorPos(11,5)
print(version)
sleep(3)
shell.run("pastebin run JuYtAwrk")
else
print("+--------------------------+")
print("|Current update owned! |")
print("+--------------------------+")
end
else
print( "Couldn't connect to pastebin!" )
end
end
updateCheck()
startscreen(print)
login()
#14
Posted 09 November 2015 - 01:36 AM
What error do you get if you run it in Minecraft instead of an emulator?
#15
Posted 11 November 2015 - 09:32 PM
I never tried. been away from my computer just coding on my phone. Ill post results in a bit. thanks never occur'd to me.
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











