Created
January 8, 2019 08:33
-
-
Save dogukancagatay/11b1fff9368815a3c248793bf448638a to your computer and use it in GitHub Desktop.
Truncgil Finans JSON API Google Sheets icin Google Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Imports currency data from Truncgil JSON API in TRY Ex: IMPORTTRUNCGIL("Çeyrek Altın") | |
* @param {string} currency_type - Type of the currency | |
* @customfunction | |
*/ | |
function IMPORTTRUNCGIL(currency_type) { | |
is_ok = false; | |
switch(currency_type) { | |
case "ABD DOLARI": | |
is_ok = true; | |
break; | |
case "AVUSTRALYA DOLARI": | |
is_ok = true; | |
break; | |
case "DANİMARKA KRONU": | |
is_ok = true; | |
break; | |
case "EURO": | |
is_ok = true; | |
break; | |
case "İNGİLİZ STERLİNİ": | |
is_ok = true; | |
break; | |
case "İSVİÇRE FRANGI": | |
is_ok = true; | |
break; | |
case "İSVEÇ KRONU": | |
is_ok = true; | |
break; | |
case "KANADA DOLARI": | |
is_ok = true; | |
break; | |
case "KUVEYT DİNARI": | |
is_ok = true; | |
break; | |
case "NORVEÇ KRONU": | |
is_ok = true; | |
break; | |
case "SUUDİ ARABİSTAN RİYALİ": | |
is_ok = true; | |
break; | |
case "JAPON YENİ": | |
is_ok = true; | |
break; | |
case "BULGAR LEVASI": | |
is_ok = true; | |
break; | |
case "RUMEN LEYİ": | |
is_ok = true; | |
break; | |
case "RUS RUBLESİ": | |
is_ok = true; | |
break; | |
case "İRAN RİYALİ": | |
is_ok = true; | |
break; | |
case "ÇİN YUANI": | |
is_ok = true; | |
break; | |
case "PAKİSTAN RUPİSİ": | |
is_ok = true; | |
break; | |
case "KATAR RİYALİ": | |
is_ok = true; | |
break; | |
case "Çeyrek Altın": | |
is_ok = true; | |
break; | |
case "Yarım Altın": | |
is_ok = true; | |
break; | |
case "Tam Altın": | |
is_ok = true; | |
break; | |
case "Cumhuriyet Altını": | |
is_ok = true; | |
break; | |
case "Ons": | |
is_ok = true; | |
break; | |
case "Gram Altın": | |
is_ok = true; | |
break; | |
case "Ata Altın": | |
is_ok = true; | |
break; | |
case "14 Ayar Altın": | |
is_ok = true; | |
break; | |
case "18 Ayar Altın": | |
is_ok = true; | |
break; | |
case "22 Ayar Bilezik": | |
is_ok = true; | |
break; | |
case "İkibuçuk Altın": | |
is_ok = true; | |
break; | |
case "Beşli Altın": | |
is_ok = true; | |
break; | |
case "Gremse Altın": | |
is_ok = true; | |
break; | |
case "Gümüş": | |
is_ok = true; | |
break; | |
default: | |
is_ok = false; | |
break; | |
} | |
try { | |
if (is_ok) { | |
var response = UrlFetchApp.fetch("https://finans.truncgil.com/today.json"); | |
var w = JSON.parse(response.getContentText()); | |
//Logger.log(w[currency_type]["Alış"]) | |
var result = w[currency_type]["Alış"]; | |
if (w[currency_type]["Tür"] == "Altın") { | |
result = result.replace(".", "").replace(",", "."); | |
} | |
return parseFloat(result); | |
} | |
return "Input type is wrong"; | |
} catch(err){ | |
Logger.log(err); | |
return "Error getting data"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment