update api kurs and function

This commit is contained in:
Daeng Deni Mardaeni 2023-09-11 15:35:05 +07:00
parent 17f5e2c111
commit c95c5b5720

View File

@ -16,22 +16,35 @@ class FrontendController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Renderable
*/
public function index()
{
if (File::exists('storage/kurs.json')) {
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
if($kurs->date != date('Y-m-d')){
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)->format('Y-m-d');
if ($date != date('Y-m-d')) {
$this->getKurs();
}
} else {
$this->getKurs();
}
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
$usd = $kurs->rates->IDR/$kurs->rates->USD;
$date = Carbon::createFromTimestamp($kurs->timestamp)->locale('id')->setTimezone('Asia/Jakarta')->translatedFormat('d F Y H:i:s');
$usd = $kurs->conversion_rate;
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')->sheet('Platform')->range('A:F')->get();
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)
->locale('id')
->setTimezone('Asia/Jakarta')
->translatedFormat('d F Y H:i:s');
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')
->sheet('Platform')
->range('A:F')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
@ -44,18 +57,29 @@ class FrontendController extends Controller
public function cakupan()
{
if (File::exists('storage/kurs.json')) {
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
if($kurs->date != date('Y-m-d')){
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)->format('Y-m-d');
if ($date != date('Y-m-d')) {
$this->getKurs();
}
} else {
$this->getKurs();
}
$json = File::get('storage/kurs.json');
$kurs = json_decode($json);
$usd = $kurs->rates->IDR/$kurs->rates->USD;
$date = Carbon::createFromTimestamp($kurs->timestamp)->locale('id')->setTimezone('Asia/Jakarta')->translatedFormat('d F Y H:i:s');
$usd = $kurs->conversion_rate;
$date = Carbon::createFromTimestamp($kurs->time_last_update_unix)
->locale('id')
->setTimezone('Asia/Jakarta')
->translatedFormat('d F Y H:i:s');
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')->sheet('Platform')->range('A:F')->get();
$sheets = Sheets::spreadsheet('1c2Uv3QVTyLzsJPE4uqqlMGNKO8z0Kqj6aEGh0uixAqA')
->sheet('Platform')
->range('A:F')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$data = new Collection($posts->toArray());
@ -65,7 +89,10 @@ class FrontendController extends Controller
public function peneliti()
{
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')->sheet('Research Proposal')->range('A:K')->get();
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')
->sheet('Research Proposal')
->range('A:K')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
@ -98,7 +125,9 @@ class FrontendController extends Controller
public function facility()
{
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')->sheet('Sequencing Facility')->get();
$sheets = Sheets::spreadsheet('1kM32QnxjRDpH1WkFSfOwMuTKzoCQpXFDYhekARcypjY')
->sheet('Sequencing Facility')
->get();
$header = $sheets->pull(0);
$posts = Sheets::collection($header, $sheets);
$posts = $posts->take(5000);
@ -145,13 +174,15 @@ class FrontendController extends Controller
{
return view('frontend::ci');
}
public function silx_ic()
{
return view('frontend::ic');
}
public function getKurs(){
$response = Http::get('http://api.exchangeratesapi.io/v1/latest?access_key=9f7cd7db5b72280a93c8e15243fadab7&symbols=USD,IDR');
public function getKurs()
{
$response = Http::get('https://v6.exchangerate-api.com/v6/7ac9163481b1e658bc0ef6a5/pair/USD/IDR');
$data = $response->json();
Storage::disk('public')->put('kurs.json', json_encode($data));
}