mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2024-12-29 00:04:35 +00:00
collapse log script
This commit is contained in:
parent
efd2e6c80e
commit
2eb6754ca4
2 changed files with 35 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
||||||
!/readme.md
|
!/readme.md
|
||||||
!/strichliste.lua
|
!/strichliste.lua
|
||||||
!/.gitignore
|
!/.gitignore
|
||||||
|
!/collapse_log.lua
|
||||||
|
|
34
collapse_log.lua
Normal file
34
collapse_log.lua
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
local function read_log()
|
||||||
|
local log = io.open("log", "r")
|
||||||
|
if log == nil then
|
||||||
|
return function() return nil end
|
||||||
|
end
|
||||||
|
local lines = log:lines("l")
|
||||||
|
return function()
|
||||||
|
local l = lines()
|
||||||
|
if l == "" or l == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local time, username, amount, comment = string.match(l, "(%d+),([%w_ -]+),(-?%d+),([%w_ -]*)")
|
||||||
|
return tonumber(time), username, tonumber(amount), comment
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function balances()
|
||||||
|
local users = {}
|
||||||
|
for _, username, amount, _ in read_log() do
|
||||||
|
users[username] = (users[username] or 0) + amount
|
||||||
|
end
|
||||||
|
return users
|
||||||
|
end
|
||||||
|
|
||||||
|
local newlog = io.open("log_collapsed","w+")
|
||||||
|
if newlog == nil then
|
||||||
|
return print("error failed to open log")
|
||||||
|
end
|
||||||
|
for username, amount in pairs(balances()) do
|
||||||
|
newlog:write(string.format("%d,%s,%d,%s\n", os.time(), username, amount, "Collapsed transaction history"))
|
||||||
|
end
|
||||||
|
newlog:close()
|
Loading…
Reference in a new issue