Blog/jokoak_euskaraz/shadow_tactics/jsons_to_csv_levels.php
(Deskargatu)
<?php
$jsons= glob("*.json");
foreach($jsons as $json)
{
if(preg_match("/lvl_/", $json))
{
$data = file_get_contents($json);
$decoded = json_decode($data,true);
array_unshift($decoded, $json, $decoded["m_Name"]);
foreach(preg_split("/[\r\n]+/", $decoded["m_Script"]) as $line)
{
$data = preg_split("/\t/", $line);
$es = @$data[3];
$data[4] = shell_exec('timeout 10s curl -s \'https://api.euskadi.eus/itzuli/es2eu/v2/translate\' -X POST -H \'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0\' -H \'Accept: application/json, text/javascript, */*; q=0.01\' -H \'Accept-Language: eu,es;q=0.8,fr;q=0.5,en-US;q=0.3\' -H \'Accept-Encoding: gzip, deflate, br, zstd\' -H \'Content-Type: application/json\' -H \'Origin: https://www.euskadi.eus\' -H \'DNT: 1\' -H \'Connection: keep-alive\' -H \'Referer: https://www.euskadi.eus/\' -H \'Sec-Fetch-Dest: empty\' -H \'Sec-Fetch-Mode: cors\' -H \'Sec-Fetch-Site: same-site\' -H \'Pragma: no-cache\' -H \'Cache-Control: no-cache\' --data-raw \'{"mkey":"8d9016025eb0a44215c7f69c2e10861d","text":'.json_encode($es).',"model":"generic_es2eu"}\' | jq -r ".translation" 2>&1 ');
array_unshift($data, $json, $decoded["m_Name"]);
$str= join("\t", $data)."\n";
$str = preg_replace("/\n+$/","",$str);
print $str."\n";
}
}
}