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

Pastebin API?

Started by DaWooShit, 02 August 2012 - 07:47 PM
DaWooShit #1
Posted 02 August 2012 - 09:47 PM
Is it possible to download from pastebin using a script?
example:


file = io.open("test.lua", "r")
if file==nil then
pastebin get Hgt6Hyt test.lua <— How do I do this part within a script
else
print("test.lua file has been found and is readable")
end
Cranium #2
Posted 02 August 2012 - 09:57 PM
There is a Http API that does just that: Right Here
MysticT #3
Posted 02 August 2012 - 10:00 PM
You can also take a look at the pastebin program, to know how it downloads the file.
This is the part for downloading:

    -- Determine file to download
    local sCode = tArgs[2]
    local sFile = tArgs[3]
    local sPath = shell.resolve( sFile )
    if fs.exists( sPath ) then
        print( "File already exists" )
        return
    end
    
    -- GET the contents from pastebin
    write( "Connecting to pastebin.com... " )
    local response = http.get(
        "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
        )
        
    if response then
        print( "Success." )
        
        local sResponse = response.readAll()
        response.close()
        
        local file = fs.open( sPath, "w" )
        file.write( sResponse )
        file.close()
        
        print( "Downloaded as "..sFile )
        
    else
        print( "Failed." )
    end
cant_delete_account #4
Posted 02 August 2012 - 10:17 PM
pastebin get Hgt6Hyt test.lua <— How do I do this part within a script


shell.run("pastebin","get","Hgt6Hyt","test.lua")
DaWooShit #5
Posted 02 August 2012 - 10:23 PM
Thanks a lot guys… Not sure why im surprised, I did went to the pro section after all :ph34r:/>/>