Added log size option
This commit is contained in:
parent
3c2ddf20e1
commit
59b177dfb2
2 changed files with 12 additions and 10 deletions
|
@ -20,7 +20,7 @@ value of the $USER environment variable as username.
|
||||||
Buy by item id (non-interactive):
|
Buy by item id (non-interactive):
|
||||||
c4mate -b|--buy <id>
|
c4mate -b|--buy <id>
|
||||||
Show log:
|
Show log:
|
||||||
c4mate -l|--log
|
c4mate -l|--log [<size>]
|
||||||
Add or subtract credits:
|
Add or subtract credits:
|
||||||
c4mate <difference>
|
c4mate <difference>
|
||||||
Give credits:
|
Give credits:
|
||||||
|
|
20
c4mate
20
c4mate
|
@ -92,15 +92,15 @@ function MatePad:update_balance()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Parse history.
|
-- Parse history.
|
||||||
function MatePad:parse_log()
|
function MatePad:parse_log(size)
|
||||||
local pipe, ok, exit, signal
|
local pipe, ok, exit, signal
|
||||||
local datefile = os.tmpname()
|
local datefile = os.tmpname()
|
||||||
local log = {}
|
local log = {}
|
||||||
-- sed #1: Insert newlines between log entries.
|
-- sed #1: Insert newlines between log entries.
|
||||||
-- sed #2: Extract time and write it into datefile. Then extract and print
|
-- sed #2: Quit after $size lines. Extract time and write it into datefile.
|
||||||
-- oldbalance, newbalance, parameter and method. Depending on method, print
|
-- Then extract and print oldbalance, newbalance, parameter and method.
|
||||||
-- either reason or item_name. If any extraction fails we fail with exit
|
-- Depending on method, print either reason or item_name. If any extraction
|
||||||
-- code 1.
|
-- fails we fail with exit code 1.
|
||||||
pipe = io.popen(string.format([=[
|
pipe = io.popen(string.format([=[
|
||||||
curl %s --header "Accept: application/json" "%s/api/user/%s/log?type=json" | \
|
curl %s --header "Accept: application/json" "%s/api/user/%s/log?type=json" | \
|
||||||
sed -n --sandbox '
|
sed -n --sandbox '
|
||||||
|
@ -109,6 +109,7 @@ sed -n --sandbox '
|
||||||
s/} *,/&\n/gp
|
s/} *,/&\n/gp
|
||||||
}' | \
|
}' | \
|
||||||
sed -n '
|
sed -n '
|
||||||
|
%d q
|
||||||
h
|
h
|
||||||
s/.*"time" *: *"\([^"]\+\)".*/\1UTC/
|
s/.*"time" *: *"\([^"]\+\)".*/\1UTC/
|
||||||
T fail
|
T fail
|
||||||
|
@ -136,7 +137,7 @@ sed -n '
|
||||||
T fail
|
T fail
|
||||||
b
|
b
|
||||||
:fail
|
:fail
|
||||||
q 1 ']=], self.CURL_FLAGS, self.HOST, url_encode(self.USER), datefile))
|
q 1 ']=], self.CURL_FLAGS, self.HOST, url_encode(self.USER), size+1, datefile))
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local entry = {}
|
local entry = {}
|
||||||
|
@ -273,7 +274,7 @@ end
|
||||||
|
|
||||||
-- Return id of last bought item in log.
|
-- Return id of last bought item in log.
|
||||||
function MatePad:last_bought()
|
function MatePad:last_bought()
|
||||||
local log = self:parse_log()
|
local log = self:parse_log(50)
|
||||||
for i = 1, #log do
|
for i = 1, #log do
|
||||||
if log[i].method == "buy" then
|
if log[i].method == "buy" then
|
||||||
return log[i].parameter
|
return log[i].parameter
|
||||||
|
@ -315,7 +316,7 @@ Find and buy item (interactive):
|
||||||
Buy by item id (non-interactive, special id '0' will re-buy last item in log):
|
Buy by item id (non-interactive, special id '0' will re-buy last item in log):
|
||||||
c4mate -b|--buy <id>
|
c4mate -b|--buy <id>
|
||||||
Show log:
|
Show log:
|
||||||
c4mate -l|--log
|
c4mate -l|--log [<size>]
|
||||||
Add or subtract credits:
|
Add or subtract credits:
|
||||||
c4mate +/-<amount>
|
c4mate +/-<amount>
|
||||||
Give credits:
|
Give credits:
|
||||||
|
@ -351,7 +352,8 @@ if arg[1] == nil then
|
||||||
elseif arg[1] == "-l" or
|
elseif arg[1] == "-l" or
|
||||||
arg[1] == "--log" then
|
arg[1] == "--log" then
|
||||||
-- Print log.
|
-- Print log.
|
||||||
pad:print_log(pad:parse_log())
|
local size = math.max(0, math.tointeger(arg[2]) or 10)
|
||||||
|
pad:print_log(pad:parse_log(size))
|
||||||
|
|
||||||
elseif arg[1] == "-g" or
|
elseif arg[1] == "-g" or
|
||||||
arg[1] == "--give" then
|
arg[1] == "--give" then
|
||||||
|
|
Loading…
Reference in a new issue