diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-02-05 00:10:23 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-02-05 00:13:21 +0300 |
commit | 1f919eaef022b4721ecb9f72a0ea703b2ac3e89a (patch) | |
tree | 53f75ef906c296b9da4598e128f677b4b926194b /fetch-messages.php |
Diffstat (limited to 'fetch-messages.php')
-rw-r--r-- | fetch-messages.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fetch-messages.php b/fetch-messages.php new file mode 100644 index 0000000..b968fbb --- /dev/null +++ b/fetch-messages.php @@ -0,0 +1,38 @@ +<?php + +require_once __DIR__.'/common.php'; + +$message_ids = array_slice($argv, 1); +if (empty($message_ids)) + fatalError('no message ids'); + +$url = 'https://api.vk.com/method/messages.getById'; +$fields = [ + 'message_ids' => implode(',', $message_ids), + 'access_token' => ACCESS_TOKEN, + 'v' => '5.109' +]; +list($code, $body) = httpPost($url, $fields); + +if ($code != 200) + fatalError('api returned '.$code); + +$response = json_decode($body, true); +if (!empty($response['error'])) + fatalError('api error: '.$response['error']['error_msg']); + +foreach ($response['response']['items'] as $item) { + $id = (int)$item['id']; + + $dir_n = $id % 100; + $cur_dir = ARCHIVE_DIR.'/messages/api/'.$dir_n; + + if (!file_exists($cur_dir)) { + if (!mkdir($cur_dir, 0755, true)) + fatalError('failed to mkdir('.$cur_dir.')'); + } + + file_put_contents($cur_dir.'/'.$id.'.txt', json_encode($item, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT)); +} + +sleep(1);
\ No newline at end of file |