Quantcast

Added get-live-data.lua to get the data

Kevin Lyles [07-04-10 - 04:04]
Added get-live-data.lua to get the data
Filename
get-live-data.lua
diff --git a/get-live-data.lua b/get-live-data.lua
new file mode 100644
index 0000000..b3322df
--- /dev/null
+++ b/get-live-data.lua
@@ -0,0 +1,75 @@
+loadfile(...)()
+
+loadfile("sort.lua")()
+
+local tbl = {
+	["^item:%d%d?%d?:0:0:0:0:0:0:0:"] = "00000_00999",
+}
+for i = 1, 99 do
+	local padded = string.sub("00" .. i, -2)
+	tbl["^item:" .. i .. "%d%d%d:0:0:0:0:0:0:0:"] = padded .. "000_" .. padded .. "999"
+end
+
+IS_invalid_items = IS_status.items.invalid
+
+local savedVars = {
+	["IS_item_info"] = {"scanned/item-info-%s.lua", tbl},
+	["IS_invalid_items"] = "scanned/invalid-items.lua",
+}
+
+for varName, fileName in pairs(savedVars) do
+	local splitType, splitParam = "none"
+	if type(fileName) == "table" then
+		fileName, splitParam = unpack(fileName)
+		if fileName:find("%%s") then
+			splitType = "string"
+		end
+	end
+	local var = _G[varName]
+	if type(var) == "number" then
+		io.output(fileName)
+		io.write(string.format("%s = %d", varName, var))
+		io.close()
+	elseif type(var) == "table" then
+		io.stdout:write(string.format("%sSaving %s...", string.rep("\8 \8", 50), varName))
+		io.stdout:flush()
+		if splitType == "none" then
+			io.output(fileName)
+			sort(var, varName)
+			io.close()
+		elseif splitType == "string" then
+			local tempArr = {}
+			for k, v in pairs(var) do
+				local c = k
+				local fileNamePart
+				for k, v in pairs(splitParam) do
+					if string.match(c, k) then
+						fileNamePart = v
+						break
+					end
+				end
+				fileNamePart = fileNamePart or "other"
+				if not tempArr[fileNamePart] then
+					tempArr[fileNamePart] = {}
+				end
+				tempArr[fileNamePart][k] = v
+			end
+			for k, v in pairs(tempArr) do
+				io.output(string.format(fileName, k))
+				if k == "" then
+					sort(v, varName)
+				else
+					sort(v, varName .. "_" .. k)
+				end
+				io.output():close()
+			end
+		else
+			io.stdout:write(string.format("\nError: Unknown splitType \"%s\" for var %q\n", splitType, varName))
+			io.stdout:flush()
+		end
+	else
+		io.stdout:write(string.format("Unhandled variable type: %q (%s)\n", type(var), varName))
+	end
+end
+
+io.stdout:write("\n")