Advertisement
incinirate

Inflation Parser

Aug 14th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. io.stdout:setvbuf("no")
  2.  
  3. local info = {}
  4. local money = 10000
  5.  
  6. for n in love.filesystem.lines("inf.csv") do
  7.     table.insert(info,n)
  8. end
  9. if not love.filesystem.isFile("yiv.csv") then
  10.     love.filesystem.newFile("yiv.csv")
  11. else
  12.     love.filesystem.write("yiv.csv","")
  13. end
  14.  
  15. function love.draw(...)
  16.     love.graphics.print("Currently writing to file...")
  17. end
  18.  
  19. function love.load(...)
  20.     for k,v in ipairs(info) do
  21.         local yearsep = v:find("%,")
  22.         local year = v:sub(1,yearsep-1)
  23.         print(year)
  24.         for nx in v:gmatch("[^%,]+") do --iterate over a ',' character
  25.             info[k] = nx:match("%s*(.*)%s*") --get rid of whitespace
  26.         end
  27.         info[k] = {year,info[k]}
  28.         if k > 1 then
  29.             if tonumber(info[k][1]) == 1959 then
  30.                 money = 10000
  31.                 info[k][3] = 10000
  32.             elseif tonumber(info[k][1]) > 1959 then
  33.                 money = money + (money*tonumber(info[k][2]))/100
  34.                 info[k][3] = money
  35.             else
  36.                 info[k][3] = money - (money*tonumber(info[k][2]))/100
  37.             end
  38.         else
  39.             info[k][3] = "10000 in 1959 is worth"
  40.         end
  41.         love.filesystem.append("yiv.csv",table.concat(info[k],",").."\n")
  42.     end
  43.     print(money)
  44.     love.event.quit()
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement