Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. -- Custom variables
  2. repo = arg[1]
  3. token = arg[2]
  4.  
  5. -- HTTP configuration
  6. headers = { ['Authorization'] = 'token ' .. token, ['Accept'] = 'application/vnd.github.v3.raw'}
  7. baseUrl = 'https://api.github.com/repos/' .. repo
  8.  
  9. -- Get all the files and directories
  10. rawTree = http.get(baseUrl .. '/git/trees/master?recursive=1', headers).readAll()
  11. files = string.gmatch(rawTree, '"path":"([^"]+)"')
  12. types = string.gmatch(rawTree, '"type":"([^"]+)"')
  13. filesDat = {}
  14. directoriesDat = {}
  15.  
  16. for file in files
  17. do
  18. type = types()
  19. if type == 'tree' then
  20. table.insert(directoriesDat, file)
  21. print('Creating a directory at ' .. file)
  22. fs.makeDir('/disk/' .. file)
  23. else
  24. table.insert(filesDat, file)
  25. print('Downloading ' .. file)
  26. data = http.get(baseUrl .. '/contents/' .. file, headers).readAll()
  27. fp = fs.open('/disk/' .. file, 'w')
  28. fp.write(data)
  29. fp.close()
  30. end
  31. end
  32.  
  33. -- Save the list of files and directories
  34. fp = fs.open('/disk/files.dat', 'w')
  35. fp.write(textutils.serialize(filesDat))
  36. fp.close()
  37. fp = fs.open('/disk/directories.dat', 'w')
  38. fp.write(textutils.serialize(directoriesDat))
  39. fp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement