-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (39 loc) · 1.11 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function rateNBP(currency,cellDate,boolDataStamp) {
var price
let date
for(let i = 1; i < 6; i++){
date = createDate(cellDate,i)
try{
let resp = UrlFetchApp.fetch(createLinkNBP(currency,date))
let content = resp.getContentText();
let jsonn = JSON.parse(content);
price = jsonn["rates"][0]['mid'];
break
}
catch(e){
continue
}
}
if(boolDataStamp){
price = price + " (" + date + ")"
}
return price
}
function createDate(date,howMuchTakeAway){
let result = new Date(date.getTime()-howMuchTakeAway*(24*3600*1000))
result = Utilities.formatDate(result,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),"yyyy-MM-dd")
return result
}
function createLinkNBP(currency,date){
let baseOfString = 'http://api.nbp.pl/api/exchangerates/rates/'
let separator = '/'
let tableType = 'a'
let format = '?format=json'
let returnString = baseOfString + tableType + separator + currency + separator + date + separator + format
return returnString
}
function convertCurrencyIfNotPln(value){
return value
if(value.indexOf("zł")>-1){return true}
return false
}