Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FILE: db.lua
- -- FUNCTION: download files from dropbox
- -- PASTEBIN: pastebin get -f qrhmgnQz db.lua
- local internet = require( "internet" )
- local term = require( "term" )
- local event = require( "event" )
- local fs = require( "filesystem" )
- local unserialize = require( "serialization" ).unserialize
- local function getList( )
- local result, response = pcall( internet.request, "https://dl.dropboxusercontent.com/s/z5q6fldyy426q3f/appList.txt?dl=1" )
- if result then
- s = ""
- for chunk in response do
- string.gsub( chunk, "\r\n", "" )
- string.gsub( chunk, "\t", "" )
- string.gsub( chunk, " ", "" )
- s = s .. chunk
- end
- return unserialize( s )
- end
- end
- local function download( file, code, path )
- if path == nil then path = "" end
- path = path .. file .. ".lua"
- local f, reason = io.open( path, "w" )
- if not f then
- io.stderr:write( "failed open " .. path .. " for writing: " .. reason )
- return
- end
- io.write( "Downloading " .. path .. " - " )
- local result, response = pcall( internet.request, "https://dl.dropboxusercontent.com/s/" .. code .. "/" .. file .. ".lua?dl=1" )
- if result then
- for chunk in response do
- string.gsub( chunk, "\r\n", "\n" )
- string.gsub( chunk, "\t", " " )
- f:write( chunk )
- end
- f:close()
- print( "Ok" )
- else
- print( "Not found" )
- end
- end
- print( "Loading app list..." )
- local list = getList()
- local apps = list.apps
- print( "------------------------" )
- for k, v in ipairs( list.apps ) do
- print( k, v[1] )
- end
- print()
- print( "Choose wisely... " )
- num = tonumber( term.read() )
- if num > 0 and num <= #apps then
- local app = list.apps[num]
- download( app[1], app[2] )
- if #app > 2 then
- if not fs.exists("api") then
- fs.makeDirectory("api")
- end
- for i = 3, #app do
- local api = list.apis[app[i]]
- if api ~= nil then
- download( app[i], api, "api/" )
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment