bigtwisty

db

Jan 9th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. -- FILE: db.lua
  2. -- FUNCTION: download files from dropbox
  3. -- PASTEBIN: pastebin get -f qrhmgnQz db.lua
  4.  
  5. local internet = require( "internet" )
  6. local term = require( "term" )
  7. local event = require( "event" )
  8. local fs = require( "filesystem" )
  9.  
  10. local unserialize = require( "serialization" ).unserialize
  11.  
  12. local function getList( )
  13. local result, response = pcall( internet.request, "https://dl.dropboxusercontent.com/s/z5q6fldyy426q3f/appList.txt?dl=1" )
  14. if result then
  15. s = ""
  16. for chunk in response do
  17. string.gsub( chunk, "\r\n", "" )
  18. string.gsub( chunk, "\t", "" )
  19. string.gsub( chunk, " ", "" )
  20. s = s .. chunk
  21. end
  22. return unserialize( s )
  23. end
  24. end
  25.  
  26. local function download( file, code, path )
  27. if path == nil then path = "" end
  28. path = path .. file .. ".lua"
  29. local f, reason = io.open( path, "w" )
  30. if not f then
  31. io.stderr:write( "failed open " .. path .. " for writing: " .. reason )
  32. return
  33. end
  34. io.write( "Downloading " .. path .. " - " )
  35.  
  36. local result, response = pcall( internet.request, "https://dl.dropboxusercontent.com/s/" .. code .. "/" .. file .. ".lua?dl=1" )
  37. if result then
  38. for chunk in response do
  39. string.gsub( chunk, "\r\n", "\n" )
  40. string.gsub( chunk, "\t", " " )
  41. f:write( chunk )
  42. end
  43. f:close()
  44. print( "Ok" )
  45. else
  46. print( "Not found" )
  47. end
  48. end
  49.  
  50. print( "Loading app list..." )
  51. local list = getList()
  52. local apps = list.apps
  53. print( "------------------------" )
  54. for k, v in ipairs( list.apps ) do
  55. print( k, v[1] )
  56. end
  57. print()
  58. print( "Choose wisely... " )
  59. num = tonumber( term.read() )
  60. if num > 0 and num <= #apps then
  61. local app = list.apps[num]
  62. download( app[1], app[2] )
  63. if #app > 2 then
  64. if not fs.exists("api") then
  65. fs.makeDirectory("api")
  66. end
  67. for i = 3, #app do
  68. local api = list.apis[app[i]]
  69. if api ~= nil then
  70. download( app[i], api, "api/" )
  71. end
  72. end
  73. end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment