Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --API Made for downloading various things via the HTTP API
- function dropboxGet(fileName,path,userId)
- if userId == nil then
- local iDropboxUser = 2813860
- else
- iDropboxUser = userId
- end
- local sVersion = string.sub(os.version(), -3)
- local fileGet = {}
- if sVersion == "1.4" then
- fileGet = http.get("https://dl.dropbox.com/u/" .. iDropboxUser .. "/" .. fileName)
- else
- fileGet = http.get("http://dl.dropbox.com/u/" .. iDropboxUser .. "/" ..fileName)
- end
- if path ~= nil then
- if fs.exists(path) == true then
- fs.delete(path)
- end
- local tFile = fs.open(path, "w")
- tFile.write(fileGet.readAll())
- tFile.close()
- fileGet.close()
- return true
- elseif path == nil then
- return fileGet.readAll()
- end
- end
- function githubGet(user, repo, branch, file, saveas)
- local response = http.get("raw.github.com/" ..user.. "/" ..repo.. "/" ..branch.. "/" ..file)
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( saveas, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- print("Something went wrong!")
- return false
- end
- end
- function hastebinGet(code,path)
- local sCode = code
- local sFile = path
- if sFile ~= nil then
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- fs.delete(sPath)
- end
- local response = http.get(
- "http://www.hastebin.com/raw/"..textutils.urlEncode(sCode)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- return false
- end
- elseif sFile == nil then
- local response = http.get(
- "http://www.hastebin.com/raw/"..textutils.urlEncode(sCode)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- return sResponse
- end
- end
- end
- function pastebinGet(code,path)
- local sCode = code
- local sFile = path
- if sFile ~= nil then
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- fs.delete(sPath)
- end
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- return false
- end
- elseif sFile == nil then
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- return sResponse
- end
- end
- end
Add Comment
Please, Sign In to add comment