From c0354b250f84d578b609a7f25d71dee7fc24e9ca Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 22 Aug 2023 15:01:03 +0200 Subject: currency, save/load --- db/_generated/currencies.json | 1 + db/currencies/currencies.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 db/_generated/currencies.json create mode 100644 db/currencies/currencies.php (limited to 'db') diff --git a/db/_generated/currencies.json b/db/_generated/currencies.json new file mode 100644 index 0000000..d3dc796 --- /dev/null +++ b/db/_generated/currencies.json @@ -0,0 +1 @@ +{"last_updated":"2023-08-21","map":{"AUD":{"rate":1.6995,"symbol":"$","name":"Australian Dollar","decimals":2},"BGN":{"rate":1.9558,"symbol":"\u043b\u0432","name":"Bulgarian Lev","decimals":2},"BRL":{"rate":5.414,"symbol":"R$","name":"Brazilian Real","decimals":2},"CAD":{"rate":1.4723,"symbol":"$","name":"Canadian Dollar","decimals":2},"CHF":{"rate":0.9588,"symbol":"CHF","name":"Swiss Franc","decimals":2},"CNY":{"rate":7.9456,"symbol":"\u00a5","name":"Chinese Yuan","decimals":2},"CZK":{"rate":24.02,"symbol":"K\u010d","name":"Czech Republic Koruna","decimals":2},"DKK":{"rate":7.4524,"symbol":"kr","name":"Danish Krone","decimals":2},"GBP":{"rate":0.85475,"symbol":"\u00a3","name":"British Pound Sterling","decimals":2},"HKD":{"rate":8.5488,"symbol":"$","name":"Hong Kong Dollar","decimals":2},"HUF":{"rate":381.73,"symbol":"Ft","name":"Hungarian Forint","decimals":2},"IDR":{"rate":16718,"symbol":"Rp","name":"Indonesian Rupiah","decimals":2},"ILS":{"rate":4.1395,"symbol":"\u20aa","name":"Israeli New Sheqel","decimals":2},"INR":{"rate":90.66,"symbol":"\u20b9","name":"Indian Rupee","decimals":2},"ISK":{"rate":143.7,"symbol":"kr","name":"Icelandic Kr\u00f3na","decimals":2},"JPY":{"rate":159.15,"symbol":"\u00a5","name":"Japanese Yen","decimals":0},"KRW":{"rate":1460.32,"symbol":"\u20a9","name":"South Korean Won","decimals":2},"MXN":{"rate":18.5927,"symbol":"$","name":"Mexican Peso","decimals":2},"MYR":{"rate":5.0706,"symbol":"RM","name":"Malaysian Ringgit","decimals":2},"NOK":{"rate":11.5205,"symbol":"kr","name":"Norwegian Krone","decimals":2},"NZD":{"rate":1.8407,"symbol":"$","name":"New Zealand Dollar","decimals":2},"PHP":{"rate":61.543,"symbol":"\u20b1","name":"Philippine Peso","decimals":2},"PLN":{"rate":4.4785,"symbol":"z\u0142","name":"Polish Zloty","decimals":2},"RON":{"rate":4.9406,"symbol":"lei","name":"Romanian Leu","decimals":2},"SEK":{"rate":11.9095,"symbol":"kr","name":"Swedish Krona","decimals":2},"SGD":{"rate":1.4791,"symbol":"S$","name":"Singapore Dollar","decimals":2},"THB":{"rate":38.314,"symbol":"\u0e3f","name":"Thai Baht","decimals":2},"TRY":{"rate":29.63,"symbol":"\u20ba","name":"Turkish Lira","decimals":2},"USD":{"rate":1.0908,"symbol":"$","name":"United States Dollar","decimals":2},"ZAR":{"rate":20.676,"symbol":"R","name":"South African Rand","decimals":2},"EUR":{"rate":1,"symbol":"\u20ac","name":"Euro","decimals":2}}} \ No newline at end of file diff --git a/db/currencies/currencies.php b/db/currencies/currencies.php new file mode 100644 index 0000000..7c8b2ac --- /dev/null +++ b/db/currencies/currencies.php @@ -0,0 +1,42 @@ + 0, +]; + +$currencies = []; +$apiResponse = json_decode(file_get_contents('https://api.frankfurter.app/latest?base=eur'), true); +$currencies['last_updated'] = $apiResponse['date']; +foreach ($apiResponse['rates'] as $code => $rate) { + $currencies['map'][$code] = [ + 'rate' => $rate, + 'symbol' => $currencySymbols[$code], + 'name' => $currencyNames[$code], + 'decimals' => $decimals[$code] ?? 2, + ]; +} + +// add EUR +$currencies['map']['EUR'] = [ + 'rate' => 1, + 'symbol' => $currencySymbols['EUR'], + 'name' => $currencyNames['EUR'], + 'decimals' => 2, +]; + +file_put_contents( + dirname(__DIR__) . '/_generated/currencies.json', + json_encode($currencies) +); -- cgit v1.2.3