Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Begin - Download repository
- get folders
- get files
- IF files
- download files
- IF folders
- WHILE (#folders > 0)
- get folders
- get files
- IF files
- download files
- END WHILE
- ]]
- local folders = {}
- local files = {}
- local args = {
- Authorization = "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"
- }
- local function get_folders(url)
- print("geting folders")
- local response = http.get(url, args)
- local contents = textutils.unserialiseJSON(response.readAll())
- --check for folders
- for i = 1, #contents, 1 do
- if contents[i].type == "dir" then
- folders[#folders + 1] = contents[i]
- end
- end
- end
- local function get_files(url)
- print("geting files")
- local response = http.get(url, args)
- local contents = textutils.unserialiseJSON(response.readAll())
- --check for folders
- for i = 1, #contents, 1 do
- if contents[i].type =="file" then
- files[#files + 1] = contents[i]
- end
- end
- end
- local function download_File(url, path)
- print("downloading: " .. path)
- local content = http.get(url, args).readAll()
- local file = fs.open(path, "w")
- file.write(content)
- file.close()
- end
- local function Main()
- --const
- local owner = "DYankee"
- local repo = "LapOs"
- local baseUrl = "https://api.github.com/repos/" .. owner .. "/" .. repo .. "/contents/"
- local basepath = "Lapos/"
- get_folders(baseUrl)
- get_files(baseUrl)
- if #files > 0 then
- while #files > 0 do
- local index = #files
- download_File(files[#files].url, basepath .. files[#files].path)
- table.remove(files, index)
- end
- print("no files")
- end
- if #folders > 0 then
- while #folders > 0 do
- get_files(baseUrl .. folders[#folders].path)
- if #files > 0 then
- while #files > 0 do
- download_File(files[#files].url, basepath .. files[#files].path)
- table.remove(files, #files)
- end
- end
- local index = #folders
- get_folders(baseUrl .. folders[#folders].path)
- table.remove(folders, index)
- end
- end
- print("finished")
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement