Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Mozesz tez uzyc publicznej wersji pod adresem:
- // https://teleit.pl/wyk.php?id=[id_znaleziska]&s=[rozdzielczosc]
- // np. http://teleit.pl/wyk.php?id=5454911&s=16
- $id = $_SERVER['argv'][1] ?? ($_GET['id'] ?? false);
- if(!$id)
- print 'ups...';
- $res = $_SERVER['argv'][2] ?? ($_GET['s'] >= 10 ? $_GET['s'] : 13);
- define('API_KEY','wpisz_swoj_api_key');
- define('API_SECRET','wpis_swoj_api_secret');
- define('API_URL','https://a2.wykop.pl/');
- $votes = ['up' => 'Links/Upvoters/','down' => 'Links/Downvoters/'];
- function get_curl($method, $parameters, $return_transfer = true, $is_post = false)
- {
- $curl_options = [
- CURLOPT_URL => API_URL . $method . (!empty($parameters) ? '?' . http_build_query($parameters) : ''),
- CURLOPT_RETURNTRANSFER => $return_transfer,
- CURLOPT_SSL_VERIFYHOST => 0,
- CURLOPT_SSL_VERIFYPEER => 0,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HEADER => false,
- CURLOPT_AUTOREFERER => true,
- CURLOPT_CONNECTTIMEOUT => 15,
- CURLOPT_TIMEOUT => 15,
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_POST => $is_post,
- CURLOPT_POSTFIELDS => $is_post??"",
- ];
- $curl_options[CURLOPT_HTTPHEADER] = ['Content-Type: application/json','apisign: ' .md5(API_SECRET . $curl_options[CURLOPT_URL])];
- $ch = curl_init();
- curl_setopt_array($ch, $curl_options);
- return $ch;
- }
- function get_votes($votes_sub_url)
- {
- $ch = get_curl($votes_sub_url . $id . '/appkey/' . API_KEY . '/format/json', [], true, false);
- $result = curl_exec($ch);
- if (curl_errno($ch)) {
- $error_msg = curl_error($ch);
- throw new Exception("Error Processing Request - curl: " . $error_msg, 1);
- }
- curl_close($ch);
- return json_decode($result)->data ?? [];
- }
- $ch_data = ['up' => get_votes($votes['up'] . $id), 'down' => get_votes($votes['down'] . $id)];
- $tmp = ['up' => 0, 'down' => 0];
- $data = [];
- foreach($ch_data as $k=>$v)
- {
- foreach ($ch_data[$k] as $value) {
- $k_tmp = substr($value->date,0,$res);
- $data[$k_tmp] ?? $data[$k_tmp] = $tmp;
- $data[$k_tmp][$k]++;
- }
- }
- ksort($data);
- print '<pre>';
- foreach ($data as $key => $value) {
- print $key . ' up: ' . str_pad($data[$key]['up'],5,'.', STR_PAD_LEFT) . ' down: ' . str_pad($data[$key]['down'],5,'.', STR_PAD_LEFT) . PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement