5 loadfile("fileutil.lua")()
7 local base_directory = "~/QuestHelper-SpiderData"
9 function searchFile(file, str)
10 local stream = io.popen(string.format("grep %s -ce %s", FileUtil.quoteFile(file), FileUtil.quoteFile(str)))
12 local number = tonumber(stream:read())
19 function fileType(file)
20 local stream = io.popen(string.format("file -bi %s", FileUtil.quoteFile(file)))
22 local filetype = stream:read()
24 return filetype or "unknown"
37 local wd_loader = loadfile("External/wowdata.lua")
40 print("Loading old data.")
42 setfenv(wd_loader, env)
46 WoWData = env.WoWData or WoWData
50 local stream = io.open("External/wowdata.lua", "w")
51 local buffer, prebuf = CreateBuffer(), CreateBuffer()
52 DumpVariable(buffer, prebuf, WoWData, "WoWData")
53 stream:write(DumpingComplete(buffer, prebuf))
58 local q = WoWData.quest[id]
59 if not q then q = {name={},hash={},faction={}} WoWData.quest[id] = q end
64 local n = WoWData.npc[id]
65 if not n then n = {name={}} WoWData.npc[id] = n end
70 local i = WoWData.item[id]
71 if not i then i = {name={}} WoWData.item[id] = i end
76 if tag == "br /" then return "\n" end
77 print("Unknown Tag: "..tag)
80 function doEntity(entity)
81 if tag == "amp" then return "&" end
82 if tag == "lt" then return "<" end
83 if tag == "gt" then return ">" end
84 print("Unknown Entity: "..tag)
87 function htmlToText(input)
88 return string.gsub(string.gsub(input, "<(.-)>", doTag), "&(.-);", doEntity)
91 function preFix(str, pre)
94 local t = select(3, string.find(str, pre))
103 function hashString(text)
104 -- Computes an Adler-32 checksum.
106 for i=1,string.len(text) do
107 a = (a+string.byte(text,i))%65521
113 function downloadItems()
116 local map = {de ="deDE", en = "enUS", es = "esES", fr = "frFR", ko="koKR", zh="zhCN"}
118 FileUtil.createDirectory(base_directory)
119 FileUtil.createDirectory(base_directory.."/items")
121 while failures < 256 do
126 local destfile = base_directory.."/items/"..index
128 if (FileUtil.fileExists(destfile) or
129 os.execute(string.format("wget %s -q -N -O %s",
130 FileUtil.quoteFile("http://www.wowguru.com/db/syndicate/items/id"..index..".xml"),
131 FileUtil.quoteFile(destfile))) == 0) and fileType(destfile) == "text/xml" then
132 local xml = XMLtoLUA(destfile)
134 if xml.item and xml.item.translations then
135 local i = getItem(index)
136 if xml.item.translations then
137 local t = xml.item.translations
138 for t, x in pairs(xml.item.translations) do
140 print(index, map[t], x.value)
141 i.name[map[t]] = x.value
153 failures = failures + 1
160 function downloadNPCs()
164 deDE = "http://de.wowguru.com/db/syndicate/mobs/id%d.xml",
165 enUS = "http://www.wowguru.com/db/syndicate/mobs/id%d.xml",
166 frFR = "http://fr.wowguru.com/db/syndicate/mobs/id%d.xml",
167 koKR = "http://ko.wowguru.com/db/syndicate/mobs/id%d.xml",
168 zhCN = "http://zh.wowguru.com/db/syndicate/mobs/id%d.xml",
169 esES = "http://es.wowguru.com/db/syndicate/mobs/id%d.xml"
172 FileUtil.createDirectory(base_directory)
173 FileUtil.createDirectory(base_directory.."/npcs")
174 for locale in pairs(map) do
175 FileUtil.createDirectory(base_directory.."/npcs/"..locale)
178 while failures < 256 do
181 for locale, url_format in pairs(map) do
182 local destfile = base_directory.."/npcs/"..locale.."/"..index
184 if (FileUtil.fileExists(destfile) or
185 os.execute(string.format("wget %s -q -N -O %s",
186 FileUtil.quoteFile(string.format(url_format, index)),
187 FileUtil.quoteFile(destfile))) == 0) and fileType(destfile) == "text/xml" then
188 local xml = XMLtoLUA(destfile)
190 if xml.mob and type(xml.mob.name) == "string" then
191 local npc = getNPC(index)
193 print(index, locale, xml.mob.name)
195 npc.name[locale] = xml.mob.name
205 failures = failures + 1
212 function downloadQuests()
216 enUS = "http://www.wowguru.com/db/quests/id%d/",
217 frFR = "http://fr.wowguru.com/db/quests/id%d/",
218 esES = "http://es.wowguru.com/db/quests/id%d/",
219 deDE = "http://de.wowguru.com/db/quests/id%d/",
220 zhCN = "http://zh.wowguru.com/db/quests/id%d/",
221 koKR = "http://ko.wowguru.com/db/quests/id%d/"
224 FileUtil.createDirectory(base_directory)
225 FileUtil.createDirectory(base_directory.."/quests")
226 for locale in pairs(map) do
227 FileUtil.createDirectory(base_directory.."/quests/"..locale)
230 while failures < 256 do
233 for locale, url_format in pairs(map) do
234 local destfile = base_directory.."/quests/"..locale.."/"..index
236 if (FileUtil.fileExists(destfile) or
237 os.execute(string.format("wget %s -q -N -O %s",
238 FileUtil.quoteFile(string.format(url_format, index)),
239 FileUtil.quoteFile(destfile))) == 0) and searchFile(destfile, "<td id=\"filecontent\">") > 0 then
240 local file = io.open(FileUtil.fileName(destfile), "r")
242 local data = correctText(file:read("*a"))
245 local name, desc, req, faction, level, begin_index, begin_name, ends_index, end_name
246 name, data = select(3, string.find(data, "</h3><h3>%s*([^\n]-)%s*</h3>(.*)"))
247 desc, data = select(3, string.find(data or "", "<h2>.-</h2>%s*<blockquote>%s*(.-)%s*</blockquote>(.*)"))
248 req, data = select(3, string.find(data or "", "<h2>.-</h2>%s*<blockquote>%s*(.-)%s*</blockquote>(.*)"))
250 local obj_table, data2 = select(3, string.find(data or "", "^%s-<table>(.-)</table>(.*)"))
254 string.gsub(obj_table, "<a href=\"/db/(.-)/.-%-id(%d-)\">%s-(.-)%s-</a>", function (t, index, name)
255 index = tonumber(index)
256 if index and name ~= "" then
258 local i = getItem(index)
260 i.name[locale] = i.name[locale] or name
261 print("QUEST ITEM: "..name)
262 elseif t == "mobs" then
263 local n = getNPC(index)
265 n.name[locale] = n.name[locale] or name
266 print("QUEST_MONSTER: "..name)
272 faction = preFix(select(3, string.find(data or "", ">([^\n]-)</div><strong>Faction")), ">(.*)")
273 level = tonumber(preFix(select(3, string.find(data or "", ">([^\n]-)</div><strong>Level")), ">(.*)"))
275 local chunk = preFix(select(3, string.find(data or "", "href=\"(.-)</a></div><strong>Begins")), "href=\"(.*)")
276 begin_id = tonumber(preFix(select(3, string.find(chunk or "", "-id([%d]+)\"")), "-id(.*)"))
277 begin_name = preFix(select(3, string.find(chunk or "", ">([^\n]+)$")), ">(.*)")
278 chunk = preFix(select(3, string.find(data or "", "href=\"(.-)</a></div><strong>Ends")), "href=\"(.*)")
279 end_id = tonumber(preFix(select(3, string.find(chunk or "", "-id([%d]+)\"")), "-id(.*)"))
280 end_name = preFix(select(3, string.find(chunk or "", ">([^\n]+)$")), ">(.*)")
282 chunk = select(3, string.find(data or "", "<ol>(.-)</ol>"))
287 string.gsub(chunk, "<li(.-)</li>", function (chunk)
288 local id = select(3, string.find(chunk, "%[%d+%].-%-id(%d+)/"))
299 local before = getQuest(i)
300 local after = getQuest(i+1)
302 local before_id, after_id = map[i], map[i+1]
304 if before_id and after_id then
305 before.next = after_id
306 after.prev = before_id
313 print("--- Quest "..locale.."/"..index.." ---")
314 print("NAME: "..htmlToText(name or "???"))
315 print("DESC: "..htmlToText(desc or "???"))
316 print("REQ: "..htmlToText(req or "???"))
317 print("FACTION: "..htmlToText(faction or "???"))
318 print("LEVEL: "..(level or "???"))
319 print("BEGIN: "..htmlToText((begin_name or "???").." (#"..(begin_id or "???")..")"))
320 print("END: "..htmlToText((end_name or "???").." (#"..(end_id or "???")..")"))
322 if name and name ~= "" and level then
323 local q = getQuest(index)
324 q.name[locale] = name
326 if req then q.hash[locale] = hashString(req) end
328 if faction == "Alliance" then
330 elseif faction == "Horde" then
332 elseif faction == "N/A" then
333 -- Don't know who the quest is for, factions will be added if we've seen someone do the quest.
335 print("!!!!!!!!!!!", "UNKNOWN FACTION", faction)
339 if begin_id and begin_name and begin_name ~= "" then
340 local n = getNPC(begin_id)
342 n.name[locale] = begin_name
346 if end_id and end_name and end_name ~= "" then
347 local n = getNPC(end_id)
349 n.name[locale] = end_name
362 failures = failures + 1