打开/关闭菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:SteamPrice:修订间差异

来自骷髅女孩Wiki
创建页面,内容为“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"].dat…”
 
无编辑摘要
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
local p = {}
local p = {}
local http = require("socket.http")
local dkjson = require("dkjson")
local ltn12 = require("ltn12")
 
local json = require("dkjson")
-- JSON字符串
local url = "https://store.steampowered.com/api/appdetails?appids=245170&cc=cn&filters=price_overview"
local json_str = [[
local response = {}
{
local res, code, response_headers, status = http.request{
  "245170": {
     url = url,
    "success": true,
    sink = ltn12.sink.table(response)
    "data": {
      "price_overview": {
        "currency": "CNY",
        "initial": 8000,
        "final": 8000,
        "discount_percent": 0,
        "initial_formatted": "",
        "final_formatted": "¥ 80.00"
      }
     }
  }
}
}
]]
-- 解析JSON字符串
local data = dkjson.decode(json_str)


if code == 200 then
-- 提取价格信息
    local data = json.decode(table.concat(response))
local appid = "245170"
    local priceOverview = data["245170"].data.price_overview
local priceOverview = data[appid].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()
function p.discount()

2025年1月14日 (二) 22:41的最新版本

此模块的文档可以在模块:SteamPrice/doc创建

local p = {}
local dkjson = require("dkjson")

-- JSON字符串
local json_str = [[
{
  "245170": {
    "success": true,
    "data": {
      "price_overview": {
        "currency": "CNY",
        "initial": 8000,
        "final": 8000,
        "discount_percent": 0,
        "initial_formatted": "",
        "final_formatted": "¥ 80.00"
      }
    }
  }
}
]]

-- 解析JSON字符串
local data = dkjson.decode(json_str)

-- 提取价格信息
local appid = "245170"
local priceOverview = data[appid].data.price_overview

function p.discount()
	return string.format('%s', priceOverview.discount_percent)
end

function p.price()
	return string.format('%s', priceOverview.final)
end
return p