此模块的文档可以在模块:SteamPrice/doc创建
local p = {}
local http = require("socket.http")
local ltn12 = require("ltn12")
local json = require("dkjson")
local url = "https://store.steampowered.com/api/appdetails?appids=245170&cc=cn&filters=price_overview"
local response = {}
local res, code, response_headers, status = http.request{
url = url,
sink = ltn12.sink.table(response)
}
if code == 200 then
local data = json.decode(table.concat(response))
local priceOverview = data["245170"].data.price_overview
print("货币单位: " .. priceOverview.currency)
print("初始价格: " .. priceOverview.initial / 100 .. "元")
print("最终价格: " .. priceOverview.final / 100 .. "元")
print("折扣百分比: " .. priceOverview.discount_percent .. "%")
print("格式化的最终价格: " .. priceOverview.final_formatted)
else
print("请求失败,状态码: " .. code)
end
function p.discount()
return string.format('%s', priceOverview.discount_percent)
end
function p.price()
return string.format('%s', priceOverview.final)
end
return p