ClocxHD

Untitled

Oct 18th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. $app->get('/bot/quotes/json', function () use ($app) {
  4.     require 'data.php';
  5.     try
  6.     {
  7.         $client = new GuzzleHttp\Client([
  8.             'headers' => [
  9.                 'webauth' => webauth
  10.             ]
  11.         ]);
  12.         $response = $client->get('http://' . host . ':' . port . '/dbquery?table=quotes&getKeys');
  13.         $result = $response->getBody();
  14.         $object = json_decode($result);
  15.  
  16.         $quotes = array();
  17.         foreach($object->table->keylist as $key=>$keys)
  18.         {
  19.             $response = $client->get('http://' . host . ':' . port . '/dbquery?table=quotes&getData=' . $key);
  20.             $result = $response->getBody();
  21.             $object = json_decode($result);
  22.             $timestamp = (json_decode($object->table->value)[2]) / 1000;
  23.             $datum = date('d.m.Y, H:i:s', $timestamp);
  24.             $src = json_decode($object->table->value);
  25.             $quotes[$key] = array_replace($src, array(2 => $datum));
  26.         }
  27.     }
  28.     catch (ClientException $e)
  29.     {
  30.         $response = $e->getResponse();
  31.         $result = $response->getBody();
  32.         $object = json_decode($result);
  33.         echo "Exception has occurred: ". $object->{'error'};
  34.     }
  35.  
  36.     return json_encode($quotes, JSON_FORCE_OBJECT);
  37. });
Advertisement
Add Comment
Please, Sign In to add comment