Created
January 8, 2020 11:52
-
-
Save MrMeison/f3d6ccf03711b80fb55b6b4705a42184 to your computer and use it in GitHub Desktop.
Формула для Google Sheets для получения инфляции в стране за произвольный период
This file contains hidden or 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
var ENTRYPOINT = "https://www.statbureau.org/calculate-inflation-rate-json"; | |
/** | |
* Получаем инфлацию за произвольный период | |
* | |
* @param {string} country - страна (belarus, brazil, canada, european-union, eurozone, france, germany, greece, india, japan, kazakhstan, mexico, russia, spain, turkey, ukraine, united-kingdom, united-states) | |
* @param {Date} start - первый месяц, включительно | |
* @param {Date} end - последний месяц, включительно | |
* @return Получаем инфляцию за произвольный период | |
* @customfunction | |
*/ | |
function GET_INFLATION(country, start, end) { | |
// корекция на MSK | |
start.setDate(start.getDate() + 1); | |
var data = { | |
'country': country, | |
'start': Utilities.formatDate(start, "MSK", "yyyy/MM/dd"), | |
'end': Utilities.formatDate(end, "MSK", "yyyy/MM/dd") | |
}; | |
var options = { | |
'method' : 'post', | |
'contentType': 'application/json', | |
'payload' : JSON.stringify(data), | |
'escaping': false | |
}; | |
var response = UrlFetchApp.fetch(ENTRYPOINT, options); | |
var result = response.getContentText().replace(/"/gi,''); | |
return Number(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment