local updateonly ---- Set this to something to update only this battlegroup. Syntax is rootpage..battlegroup updateonly = "http://armory.worldofwarcraft.com/Retaliation" ---- Sets the max number of teams that the miner will try to get per bracket (per battlegroup) local max_num_teams = 5000000 local classes = { Druid = 1, Hunter = 2, Mage = 3, Paladin = 4, Priest = 5, Rogue = 6, Shaman = 7, Warlock = 8, Warrior = 9, } local talenttreelengths = { Druid = {21,21}, Hunter = {21,20}, Mage = {23,22}, Paladin = {20,21}, Priest = {21,21}, Rogue = {21,24}, Shaman = {20,21}, Warlock = {21,22}, Warrior = {23,21}, } local eu_root = "http://armory.wow-europe.com/" local us_root = "http://armory.worldofwarcraft.com/" local teamsizes = {2,3,5} http = require("socket.http") http.USERAGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" url = require("socket.url") Tattle = {} --~ loadfile('data.lua')() local mt mt = {__index = function(t,k) if not k then print(debugstack()) end t[k] = setmetatable({},mt) return t[k] end} local eu_data = setmetatable({},mt) local us_data = setmetatable({},mt) local recurseassignmeta function recurseassignmeta(t) t = setmetatable(t, mt) for _,v in pairs(t) do if type(v) == 'table' then recurseassignmeta(v) end end end eu_data = Tattle.EUData or {} us_data = Tattle.USData or {} resumedata = Tattle.resumedata or {} recurseassignmeta(eu_data) recurseassignmeta(us_data) local key = {"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"} key[0] = "0" local function to36(data) if not tonumber(data) then return data end local working = tonumber(data) local newstr = "" if working == 0 then newstr = "0" end while working > 0 do newstr = key[working%36]..newstr working = math.floor(working / 36) end return newstr end local f local starttime = os.time() local pagecache = setmetatable({},{__mode="v"}) local pagerequests = 0 local function getpage(address) if pagecache[address] then return pagecache[address] end local p,e for i = 1, 10 do pagerequests = pagerequests + 1 p, e = http.request(address) if p then pagecache[address] = p return p end end error('failed'..address..e) end local function makeprettydatestring() local d = os.date('*t') return d.month..'/'..d.day..'/'..d.year..' '..d.hour..':'..d.min end local function getnum(block) local n = 0 for i = 1, block:len() do n = n + tonumber(block:sub(i,i)) end return n end local function escape(str) local new = "" local ch=false for i = 1, str:len() do local char = str:sub(i,i) if string.byte(char) >= 128 then ch=true new = new..string.char(92)..string.byte(char) else new = new..char end end if new:match("'") or new:match(" ") or new:match("-") then ch = true end if new:match('"') then new:gsub('"', string.char(92)..'"') ch = true end return new,ch end local function writekeyline(tabs, key, data,f) local ch key, ch = escape(key) if ch or key:match('%d') then f:write((" "):rep(tabs)..'["'..key..'"] = "'..escape(tostring(data))..'",\n') else f:write((" "):rep(tabs)..key..' = "'..escape(tostring(data))..'",\n') end end local writetable function writetable(tabs, name, t,f) local srt = {} for k in pairs(t) do srt[#srt+1] = k end table.sort(srt) if tabs > 0 then f:write((" "):rep(tabs)..'["'..escape(name)..'"] = {\n') else f:write(escape(name)..' = {\n') end for _,k in ipairs(srt) do if type(t[k]) == 'table' then writetable(tabs+1,k,t[k],f) else writekeyline(tabs+1,k,t[k],f) end end f:write((" "):rep(tabs).."}"..(tabs>0 and "," or "").."\n") end local usbattlegroupsincrement = 1 local eubattlegroupsincrement = 1 local battlegroupdata = { US = {}, EU = {}, } local function writebattlegroupfile(region,battlegroup,data) local filenum if region == "US" then filenum = usbattlegroupsincrement usbattlegroupsincrement = usbattlegroupsincrement + 1 elseif region == "EU" then filenum = eubattlegroupsincrement eubattlegroupsincrement = eubattlegroupsincrement + 1 end local check = io.open('Gladiator_'..region..filenum..'/'..region..filenum..".lua", 'r') if check then check:close() else os.execute('mkdir Gladiator_'..region..filenum) end local file = assert(io.open('Gladiator_'..region..filenum..'/'..region..filenum..".lua", 'w')) file:write('if not Tattle then\n') file:write(' Tattle = {}\n') file:write('end\n') file:write('if not Tattle.'..region..'Data then\n') file:write(' Tattle.'..region..'Data = {}\n') file:write('end\n') writetable(0,'Tattle.'..region..'Data["'..battlegroup..'"]', data, file) file:close() local file = assert(io.open('Gladiator_'..region..filenum..'/'..'Gladiator_'..region..filenum..'.toc', 'w')) file:write('## Interface: 20100\n') file:write('## LoadOnDemand: 1\n') file:write('## Title: Gladiator Player Data - '..region..battlegroup..'\n') file:write('## Author: Nymbia\n') file:write('## Version: '..(rawget(data,Updated) or '?')..'\n\n') file:write('## X-Tattle-Data: '..battlegroup.."\n") file:write(region..filenum..'.lua\n') file:close() end local function writedata() usbattlegroupsincrement = 1 eubattlegroupsincrement = 1 print('writing data....') f = assert(io.open("data.lua", "w")) f:write('-'..'- data format: (all numbers in base 36)\n') f:write('-'..'- "teamsize:rating.ranking|team2size:rating.ranking;talentsintree1.tree2.tree3.classnumber"\n') if resumedata then writetable(0,'Tattle.resumedata',resumedata,f) end f:write('if not Tattle then\n') f:write(' Tattle = {}\n') f:write('end\n') f:write('if not Tattle.USData then\n') f:write(' Tattle.USData = {}\n') f:write('end\n') local srt = {} for k in pairs(us_data) do srt[#srt+1] = k end table.sort(srt) for _,k in ipairs(srt) do f:write('-'..'-BATTLEGROUP: US - '..k..'\n') writetable(0,'Tattle.USData["'..k..'"]', us_data[k],f) writebattlegroupfile('US',k,us_data[k]) end f:write('if not Tattle.EUData then\n') f:write(' Tattle.EUData = {}\n') f:write('end\n') local srt = {} for k in pairs(eu_data) do srt[#srt+1] = k end table.sort(srt) for _,k in ipairs(srt) do f:write('-'..'-BATTLEGROUP: EU - '..k..'\n') writetable(0,'Tattle.EUData["'..k..'"]', eu_data[k],f) writebattlegroupfile('EU',k,eu_data[k]) end local check = io.open("Gladiator_BattlegroupData/BattlegroupData.lua", "r") if check then check:close() else os.execute('mkdir Gladiator_BattlegroupData') end f:close() f = assert(io.open("Gladiator_BattlegroupData/BattlegroupData.lua", "w")) f:write('if not Tattle then\n') f:write(' Tattle = {}\n') f:write('end\n') writetable(0,'Tattle.BattlegroupData', battlegroupdata, f) f:close() f = nil print('done.') end local function doregion(root,data) print(root) local page_battlegroups = getpage(root.."battlegroups.xml") for battlegroup in page_battlegroups:gmatch(' max_num_teams and max_num_teams or num_pages local approx_num_teams = num_pages*20 local teamnum = 0 for i = 1, tonumber(num_pages) do local teamspage = getpage(root.."arena-ladder.xml?b="..url.escape(battlegroup).."&ts="..teamsize.."&p="..i.."&sf=rank&sd=a") for teamname, teamranking, teamrating, realm, teamurl in teamspage:gmatch(']+ name="([^"]+)" ranking="([^"]+)" rating="([^"]+)" realm="([^"]+)"[^>]* url="([^"]+)">') do teamnum = teamnum+1 local elapsed = os.time()- starttime print(battlegroup..' '..(root == "http://armory.worldofwarcraft.com/" and '(US)' or '(EU)')..' - '..teamsize..'v'..teamsize..': getting team '..teamnum..' of about '..approx_num_teams..". page requests: "..pagerequests..". elapsed:"..("%dm %ds"):format(elapsed/60, elapsed%60)) local teampage = getpage(root.." team-info.xml?"..teamurl:gsub("&","&")) for class, charname in teampage:gmatch(']+ class="([^"]+)" [^>]+ name="([^"]+)" race') do local old = rawget(data[battlegroup][realm], charname) if old then if not data[battlegroup][realm][charname]:match(teamsize..":") then data[battlegroup][realm][charname] = teamsize..":"..to36(teamrating).."."..to36(teamranking).."|"..old end else local talentpage = getpage(root.."character-talents.xml?r="..url.escape(realm).."&n="..url.escape(charname)) local talents = talentpage:match('>>>>US-Servers<<<<<----") do --us battlegroups local root = us_root local reg = "US" local page_battlegroups = getpage(root.."battlegroups.xml") for battlegroup, battlegroupchunk in page_battlegroups:gmatch(']+>(%D+)<%/battlegroup>') do if battlegroup ~= 'Coliseum' then for realmname in battlegroupchunk:gmatch('realm name="([^"]+)"') do battlegroupdata[reg][realmname] = battlegroup print(battlegroup.." - "..realmname) end end end end print("--->>>>>EU-Servers<<<<<----") do --eu battlegroups local root = eu_root local reg = "EU" local page_battlegroups = getpage(root.."battlegroups.xml") for battlegroup, battlegroupchunk in page_battlegroups:gmatch(']+>(%D+)<%/battlegroup>') do if battlegroup ~= 'Coliseum' then for realmname in battlegroupchunk:gmatch('realm name="([^"]+)"') do battlegroupdata[reg][realmname] = battlegroup print(battlegroup.." - "..realmname) end end end end writedata() --~ doregion(us_root,us_data) --~ doregion(eu_root,eu_data) if not updateonly then resumedata=nil end writedata()