_LINKI

GreyHack - BankParser by LINKI

Apr 21st, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. if not params or params.len < 1 or params.len > 2 then exit("<b>Example:</b> bankparser [folder] (outFile)")
  2.  
  3. myComputer = get_shell.host_computer
  4. banksFolderPath = params[0]
  5. if banksFolderPath[0] != "/" then banksFolderPath = myComputer.current_path + "/" + banksFolderPath
  6.  
  7. //Check folder//
  8. banksFolder = myComputer.File(banksFolderPath)
  9. if not banksFolder then exit("<b>Folder <i>'" + banksFolderPath + "'</i> not found</b>")
  10. if not banksFolder.is_folder then exit("<b>The path <i>'" + banksFolderPath + "'</i> does not indicate a folder</b>")
  11. banks = banksFolder.get_files
  12. if banks.len == 0 then exit("<b>Folder <i>'" + banksFolderPath + "'</i> contains no files</b>")
  13.  
  14. //Check outFilePath//
  15. if params.len == 2 then
  16.     if params[1] == "/" then exit("<b>Wrong path - <i>'" + params[1] + "'</i></b>")
  17.     if params[1][0] == "/" then
  18.         outFileParentPath = parent_path(params[1])
  19.         if outFileParentPath == "/" then
  20.             outFileDirPath = ""
  21.         else
  22.             outFileDirPath = parent_path(params[1])
  23.         end if
  24.     else
  25.         outFileDirPath = myComputer.current_path + "/" + parent_path(params[1])
  26.     end if
  27.     outFileName = params[1]
  28.     if outFileName[-1] == "/" then outFileName = outFileName[:-1]
  29.     outFileName = outFileName.split("/")[-1]
  30. else
  31.     outFileDirPath = banksFolderPath
  32.     outFileName = "Banks.txt"
  33. end if
  34. outFilePath = outFileDirPath + "/" + outFileName
  35.  
  36.  
  37. //Check outFile//
  38. outFile = myComputer.File(outFilePath)
  39. if outFile then
  40.     outFile.set_content("")
  41. else
  42.     outFileDir = myComputer.File(outFileDirPath)
  43.     if not outFileDir then exit("<b>Could not create file on path - <i>'" + outFilePath + "'</i></b>")
  44.    
  45.     myComputer.touch(outFileDirPath, outFileName)
  46.     outFile = myComputer.File(outFilePath)
  47.     if not outFile then exit("<b>Could not create file on path - <i>'" + outFilePath + "'</i></b>")
  48. end if
  49.  
  50. //Parsing//
  51. for bank in banks
  52.     if bank.path == outFile.path then
  53.         banks.remove(banks.indexOf(bank))
  54.     else
  55.         outFile.set_content(outFile.content + bank.content + "\n")
  56.     end if
  57. end for
  58. outFile.set_content(outFile.content[:-1])
  59.  
  60. print("[Parsed " + banks.len + " files to '" + outFilePath + "']")
  61. print("[Total accounts - " + outFile.content.split("\n").len + "]")
Add Comment
Please, Sign In to add comment