Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creeper9207 Code: wget substitute (API)--
- --functions:
- --openGUI
- --downloadFile
- --silentDownload
- --example:
- --os.loadAPI("wgetAPI")
- --wget.silentDownload("http://creeper9207.com/file.html", "file.html")
- function openGUI()
- term.clear()
- gui1 = paintutils.loadImage(".wget/gui1")
- paintutils.drawImage(gui1, 1, 1)
- term.setCursorPos(3, 3)
- term.setBackgroundColor( colors.lightGray )
- term.setTextColor( colors.white )
- io.write("url:")
- guiUrl = io.read()
- term.setCursorPos(3, 5)
- io.write("file:")
- guiFile = io.read()
- downloadFile(guiUrl, guiFile)
- end
- function downloadFile(url, file)
- term.setBackgroundColor( colors.black )
- term.setCursorPos(1, 1)
- background = paintutils.loadImage(".wget/background")
- paintutils.drawImage(background, 1, 1)
- print("Getting file...")
- http.request(url)
- event, eUrl, content = os.pullEvent()
- if event == "http_success" then
- print("SUCCESS!")
- body = content.readAll()
- file = fs.open(file, "w")
- file.write(body)
- file.flush()
- file.close()
- print("")
- print("downloaded!")
- elseif event == "http_failure" then
- print("download error")
- else
- print("unknown error")
- end
- end
- function silentDownload(url, file)
- http.request(url)
- event, eUrl, content = os.pullEvent()
- if event == "http_success" then
- body = content.readAll()
- file = fs.open(file, "w")
- file.write(body)
- file.flush()
- file.close()
- elseif event == "http_failure" then
- else
- end
- end
- function screenClear()
- term.setBackgroundColor( colors.black )
- term.setCursorPos(1, 1)
- background = paintutils.loadImage(".wget/background")
- paintutils.drawImage(background, 1, 1)
- end
- --os.loadAPI("wget")
- --wget.silentDownload("http://creeper9207.com/file.html", "file.html")
Advertisement
Add Comment
Please, Sign In to add comment