@@ -365,41 +365,45 @@ function TradeQueryGeneratorClass:InitMods()
365365 return
366366 end
367367
368- -- download stats JSON from GGG API
369- launch :DownloadPage (" https://www.pathofexile.com/api/trade2/data/stats" ,
370- function (response , errMsg )
371- if errMsg then
372- error (" Error while downloading stats.json: " .. errMsg )
373- end
374- local body = dkjson .decode (response .body )
375-
376- if body .error then
377- error (" Error received from api/trade2/data/stats: " .. body .error .message )
378- end
368+ -- Download stats JSON from GGG API. Do not use launch:DownloadPage here as it is async, and QueryMods.lua must use the freshly downloaded stats.
369+ local tradeStats = " "
370+ local easy = curl .easy ()
371+ easy :setopt_url (" https://www.pathofexile.com/api/trade2/data/stats" )
372+ easy :setopt_useragent (" Path of Building/" .. launch .versionNumber )
373+ easy :setopt_writefunction (function (data )
374+ tradeStats = tradeStats .. data
375+ return true
376+ end )
377+ local ok = easy :perform ()
378+ easy :close ()
379+ if not ok or tradeStats == " " then
380+ error (" Error while downloading stats.json" )
381+ end
382+ local body = dkjson .decode (tradeStats )
379383
380- local f = io.open (" ./Data/TradeSiteStats.lua" , " w" )
381- if not f then
382- error (" Could not open file for writing trade stat data" )
383- end
384+ if body .error then
385+ error (" Error received from api/trade2/data/stats: " .. body .error .message )
386+ end
384387
385- for catIdx , _ in ipairs (body .result ) do
386- table.sort (body .result [catIdx ].entries , function (a , b )
387- return a .text < b .text
388- end )
389- end
388+ local f = io.open (" ./Data/TradeSiteStats.lua" , " w" )
389+ if not f then
390+ error (" Could not open file for writing trade stat data" )
391+ end
390392
393+ for catIdx , _ in ipairs (body .result ) do
394+ table.sort (body .result [catIdx ].entries , function (a , b )
395+ return a .text < b .text
396+ end )
397+ end
391398
392- local template = [[ -- This file is automatically downloaded, do not edit!
399+ local template = [[ -- This file is automatically downloaded, do not edit!
393400-- Trade site stat data (c) Grinding Gear Games
394401-- https://www.pathofexile.com/api/trade2/data/stats
395402-- spell-checker: disable
396403return %s
397404-- spell-checker: enable]]
398- f :write (s_format (template , stringify (body .result )))
399-
400- f :close ()
401- end
402- )
405+ f :write (s_format (template , stringify (body .result )))
406+ f :close ()
403407
404408 self .modData = {
405409 [" Explicit" ] = { },
552556function TradeQueryGeneratorClass :GenerateModWeights (modsToTest )
553557 local start = GetTime ()
554558 for _ , entry in pairs (modsToTest ) do
555- if _ == " 1671376347" then
556- print (" help" )
557- end
558559 if entry [self .calcContext .itemCategory ] ~= nil then
559560 if self .alreadyWeightedMods [entry .tradeMod .id ] ~= nil then -- Don't calculate the same thing twice (can happen with corrupted vs implicit)
560561 goto continue
0 commit comments