Advertisement
imitablerabbit

github

Mar 20th, 2019
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. --[[
  2. Pull all of the files from github using the http api    
  3. --]]
  4.  
  5. local files = {
  6.     "programs/github.lua",
  7.  
  8.     "startup.lua"
  9. }
  10.  
  11. local githubURL = "https://raw.github.com/imitablerabbit/computercraft/master/"
  12.  
  13. -- Fetch a single raw file from github url
  14. function fetchFile(url, filepath)
  15.     if not url then error("missing url") end
  16.     if not filepath then error("missing file path") end
  17.  
  18.     r = http.get(url)
  19.     if not r then return false end
  20.     if r.getResponseCode() ~= 200 then
  21.         r.close()
  22.         return false
  23.     end
  24.     d = r.readAll()
  25.     r.close()
  26.     h = fs.open(filepath, "w")
  27.     h.write(d)
  28.     h.close()
  29.     return true
  30. end
  31.  
  32. for k, file in pairs(files) do
  33.     url = githubURL .. file
  34.     if not fetchFile(url, file) then
  35.         print("Error: unable to fetch file: "..file)
  36.     end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement