1
0
mirror of https://github.com/DigitalDevices/octonet.git synced 2023-10-10 13:36:52 +02:00
octonet/octoserve/var/www/scifdb.lua
2015-08-05 22:22:06 +02:00

85 lines
2.8 KiB
Lua

#!/usr/bin/lua
local SLAXML = require 'slaxdom'
local SCIFDataBase = io.open('SCIFDataBase.xml'):read("*a")
-- SLAXML:parse(SCIFDataBase,{stripWhitespace=true})
local dom = SLAXML:dom(SCIFDataBase,{ simple=false,stripWhitespace=true })
local child
local unit
local i
local j
local k
local l
local Frequency
local ManufacturerList = {}
local ManufacturerArray = {}
local ManufacturerCount = 0
for i,child in ipairs(dom.kids) do
print (i,child.name)
if child.name == "SCIFDataBase" then
for j,unit in ipairs(child.kids) do
if unit.name == "OutdoorUnit" then
local Name = unit.attr["Name"];
local Manufacturer = unit.attr["Manufacturer"];
local Type = unit.attr["Type"];
local Protocol = unit.attr["Protocol"];
if not Protocol then Protocol = "" end
if not Manufacturer then Manufacturer = "" end
if not Type then Type = "LNB" end
-- print ( " ",Name,Manufacturer,Type)
local CurManu = ManufacturerList[Manufacturer]
if not CurManu then
CurManu = { UnitList = {}, UnitCount = 0, Name = Manufacturer }
ManufacturerCount = ManufacturerCount + 1
ManufacturerList[Manufacturer] = CurManu
ManufacturerArray[ManufacturerCount] = CurManu
end
CurManu.UnitCount = CurManu.UnitCount + 1
local CurUnit = { Name = Name, Type = Type, Frequencies = {} }
CurManu.UnitList[CurManu.UnitCount] = CurUnit
local fcount = 0
for k,Frequency in ipairs(unit.kids) do
if Frequency.name == "UBSlot" then
fcount = fcount + 1
CurUnit.Frequencies[fcount] = Frequency.attr["Frequency"]
-- print(" -------------------------", Frequency.type, Frequency.name, Frequency.attr["Frequency"])
end
end
end
end
end
end
-- print(ManufacturerCount)
print("HTTP/1.1 200 ")
print("Pragma: no-cache")
print("Content-Type: application/x-javascript")
print("")
print("ManufacturerList = new Array();")
for i,CurManu in ipairs(ManufacturerArray) do
print("")
print(string.format("ManufacturerList[%d] = new Object();",i-1))
print(string.format("ManufacturerList[%d].Name = \"%s\";",i-1,CurManu.Name))
print(string.format("ManufacturerList[%d].UnitList = new Array();",i-1))
for j,CurUnit in ipairs(CurManu.UnitList) do
print("")
print(string.format("ManufacturerList[%d].UnitList[%d] = new Object();",i-1,j-1))
print(string.format("ManufacturerList[%d].UnitList[%d].Name = \"%s\";",i-1,j-1,CurUnit.Name))
print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies = new Array();",i-1,j-1))
for k,Frequency in ipairs(CurUnit.Frequencies) do
print(string.format("ManufacturerList[%d].UnitList[%d].Frequencies[%d] = %d;",i-1,j-1,k-1,Frequency))
end
end
i = i + 1
end
print("")