Answer the question
In order to leave comments, you need to log in
How to create and set up a user for Capistrano?
Hello, I set up
capistrano 3 to deploy the project,
created the deploy user, then distributed his private key to everyone from the command
. How to configure deploy correctly so that everyone uses their own key and not a shared one?
Or maybe it's not the right approach at all? I put capistrano for the first time
Thank you
Answer the question
In order to leave comments, you need to log in
In the full_response field, just text comes. How to parse - depends on the form in which you need to get the data as a result. I guess you need something like this
function makeArray($keys, $value) {
$result = [];
if (sizeof($keys) == 1) {
$key = $keys[0];
$result[$key] = $value;
} else {
$key = array_shift($keys);
$result[$key] = makeArray($keys, $value);
}
return $result;
}
$path = 'http://api.warface.ru/user/stat/?name=Элез&server=1';
$content = file_get_contents($path);
$content = json_decode($content, TRUE);
$fullResponse = $content['full_response'];
$fullResponse = explode("\n", $fullResponse);
$result = [];
foreach ($fullResponse as $string) {
$string = preg_split('/[\s]*=[\s]*/u', $string, -1, PREG_SPLIT_NO_EMPTY);
if ($string) {
preg_match_all('/[\s]*\[([^\[\]]+)\]([^\[\]]+)/', $string[0], $matches);
$keys = [];
$i = 1; $total = \sizeof($matches);
for ($i; $i < $total; $i+=2) {
$keys = [];
foreach ($matches[$i] as $num => $key) {
$keys[] = $key;
$keys[] = $matches[$i+1][$num];
}
$array = makeArray($keys, $string[1]);
$result = array_merge_recursive($result, makeArray($keys, $string[1]));
}
}
}
$content['full_response'] = $result;
echo '<pre>';
var_dump($content);
echo '</pre>';
What needs to be parsed?
You get the line:
<Sum> [stat]player_ammo_restored = 425339
<Sum> [stat]player_climb_assists = 17154
<Sum> [stat]player_climb_coops = 9321
<Sum> [stat]player_damage = 489573500
<Sum> [mode]PVE [stat]player_deaths = 22793
<Sum> [mode]PVP [stat]player_deaths = 107455
<Sum> [class]Rifleman [mode]PVP [stat]player_headshots = 38150
<Sum> [class]Medic [mode]PVE [stat]player_headshots = 40388
<Sum> [class]Medic [mode]PVP [stat]player_headshots = 4271
<Sum> [class]Recon [mode]PVE [stat]player_headshots = 129160
<Sum> [class]Recon [mode]PVP [stat]player_headshots = 5423
....
const arr = json.full_response.split('\n');
/*
[0 … 99]
0: "<Sum> [stat]player_ammo_restored = 425339"
1: "<Sum> [stat]player_climb_assists = 17154"
2: "<Sum> [stat]player_climb_coops = 9321"
3: "<Sum> [stat]player_damage = 489573500"
4: "<Sum> [mode]PVE [stat]player_deaths = 22793"
5: "<Sum> [mode]PVP [stat]player_deaths = 107455"
6: "<Sum> [class]Rifleman [mode]PVP [stat]player_headshots = 38150"
7: "<Sum> [class]Medic [mode]PVE [stat]player_headshots = 40388"
8: "<Sum> [class]Medic [mode]PVP [stat]player_headshots = 4271"
9: "<Sum> [class]Recon [mode]PVE [stat]player_headshots = 129160"
10: "<Sum> [class]Recon [mode]PVP [stat]player_headshots = 5423"
11: "<Sum> [class]Engineer [mode]PVE [stat]player_headshots = 137344"
12: "<Sum> [class]Engineer [mode]PVP [stat]player_headshots = 17705"
13: "<Sum> [class]Rifleman [mode]PVE [stat]player_headshots = 429473"
*/
arr.forEach((el) => {
if (el.indexOf('Medic') >= 0) {
window.console.log(el);
}
});
/*
<Sum> [class]Medic [mode]PVE [stat]player_headshots = 40388
<Sum> [class]Medic [mode]PVP [stat]player_headshots = 4271
<Sum> [class]Medic [mode]PVP [stat]player_hits = 286872
<Sum> [class]Medic [mode]PVE [stat]player_hits = 824486
<Sum> [class]Medic [mode]PVE [stat]player_melee_headshots = 133
<Sum> [class]Medic [mode]PVP [stat]player_melee_headshots = 37
<Sum> [class]Medic [mode]PVE [stat]player_playtime = 17714490
<Sum> [class]Medic [mode]PVP [stat]player_playtime = 12876754
*/
You just need to know that the output format is json. Then you can handle it yourself) there are no arrays here yet and no one is parsing arrays. Http always outputs text data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question