79 posts
Posted 05 March 2012 - 05:29 AM
I have been wondering for a little while, how to use http api to, say, get a program from somewhere. I have two questions on this:
1: What website does anybody know that can host a program for computercraft.
2: How to get it.
Thanks for the help!
454 posts
Location
London
Posted 05 March 2012 - 10:00 AM
1: Any website that can host user content could potentially host programs.
2:
http://www.computercraft.info/forums2/index.php?/topic/82-13-httptest
79 posts
Posted 05 March 2012 - 03:10 PM
Oh, i think i missed Espen's thing.
Also, do you know any websites it 'd be easy to only take the code i want from it?
Eg. I upload a program script to that website. Then on computercraft i get the code from the website and its mostly just my program.
454 posts
Location
London
Posted 05 March 2012 - 04:02 PM
That depends on the site; pastebins allows you to get the raw data:
http://pastebin.com/nuX33xq7A script I wrote some time ago; It uses pastebin to give the user a list of 'software' and easy access to download it.
79 posts
Posted 06 March 2012 - 02:40 AM
Okay, that was what i tried out first.
But my question for that one is: How do you seperate the script from the rest of the page??
I tried looking through your script to find it, but i couldn't.
454 posts
Location
London
Posted 06 March 2012 - 02:55 AM
That's because on my script, it uses the raw get functionality of pastebin. I get the paste, in it's original form, without any html.
If you had to filter it, though, you may have to strip it of html, and evalute > etc.
You could use the string.find function, to find two html tags:
local posA = string.find("some html", "<yourcodeisinhere>"),
local posB = string.find("some html", "</yourcodeisinhere>")
local yourCode = string.sub("some html", posA +lengthOfTag, posB)
Something like that may work. It'll certainly be specific to the site you're using, though.
79 posts
Posted 06 March 2012 - 03:46 AM
If i were to just get all my scripts from a pastebin, how would i do that using the Raw Get thing?
I looked into the script at the part, didn't understand much of it.
454 posts
Location
London
Posted 06 March 2012 - 04:14 AM
If i were to just get all my scripts from a pastebin, how would i do that using the Raw Get thing?
I looked into the script at the part, didn't understand much of it.
If you don't understand it, then you may want to play around with some other things before starting with http.
It's kind of like trying to go diving without knowing how to swim.
79 posts
Posted 06 March 2012 - 04:55 AM
Oh, i just saw, the part i didnt understand is how you were seperating the whole pastebin page from the code. Then i realised
http://pastebin.com/raw.php?i=Now, i just have to figure out how to print/save it, because its giving me an error…
Heres the code so far:
v = http.request( "http://www.pastebin.com/raw.php?i=nuX33xq7" )
print (v)
That was just a test to see if i can get the data, But it dosnt return anything, help?
454 posts
Location
London
Posted 06 March 2012 - 05:34 AM
Oh, i just saw, the part i didnt understand is how you were seperating the whole pastebin page from the code. Then i realised
http://pastebin.com/raw.php?i=Now, i just have to figure out how to print/save it, because its giving me an error…
Heres the code so far:
v = http.request( "http://www.pastebin.com/raw.php?i=nuX33xq7" )
print (v)
That was just a test to see if i can get the data, But it dosnt return anything, help?
Type 'help http' ingame.
http.request will later fire a http_success/failure event, http.get will return the data (but pause your program until it's downloaded)
79 posts
Posted 06 March 2012 - 02:32 PM
It returns a table if i do it that way.
I just need help with my code, after i get the hang of it, i remember how to use it, ect.
Thanks for your help :unsure:/>/>
I did 'help http' and it didnt say anything about what it returns.
And http.get returns a table for me, apperently.
79 posts
Posted 06 March 2012 - 10:18 PM
Nevermind, i figured it out.