Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is a simple program that gives the ability for computercraft to download files off of GitHub, similar to the
- --default pastebin program (ONLY DOES GET)
- local tArgs = {...}
- local function errorColor(text)
- local isColor = term.isColor()
- if isColor == true then
- term.setTextColor(colors.red)
- print(text)
- term.setTextColor(colors.white)
- else
- print(text)
- end
- end
- local function gitGet(user, repo, branch, path, toPath)
- local dl = http.get("https://raw.github.com/"..user.."/"..repo.."/"..branch.."/"..path)
- term.write("Connecting to GitHub.......")
- sleep(.125)
- if dl then
- print("Connected!")
- local file = dl.readAll()
- term.write("Downloading File.......")
- dl.close()
- sleep(.125)
- local check = fs.exists(toPath)
- if check == true then
- errorColor("Error: File Already Exists!")
- else
- local w = fs.open(toPath,"w")
- if w then
- w.write(file)
- w.close()
- print("Downloaded as "..toPath.."!")
- return true
- else
- w.close()
- term.write("Download Failed!")
- end
- end
- else
- errorColor("Connection Failed!")
- end
- end
- if tArgs[5] == nil then
- errorColor("Usages: github get <user> <repo> <branch> <path> <topath>")
- elseif tArgs[1] == "get" then
- if tArgs[6] ~= nil then
- gitGet(tArgs[2], tArgs[3], tArgs[4], tArgs[5], tArgs[6])
- else
- gitGet(tArgs[2], tArgs[3], tArgs[4], tArgs[5], tArgs[5])
- end
- else
- errorColor("Usages: github get <user> <repo> <branch> <path> <topath>")
- end
Advertisement
Add Comment
Please, Sign In to add comment