Skip to content

Instantly share code, notes, and snippets.

@dogukancagatay
Created January 8, 2019 08:33
Show Gist options
  • Save dogukancagatay/11b1fff9368815a3c248793bf448638a to your computer and use it in GitHub Desktop.
Save dogukancagatay/11b1fff9368815a3c248793bf448638a to your computer and use it in GitHub Desktop.
Truncgil Finans JSON API Google Sheets icin Google Apps Script
/**
* 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