| Новости | FAQ | Авторы | Документация | В действии | Библиотека |
| Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
MoKo 27.11.2014 23:45
За 100% правильность не ручаюсь, но вроде как такой код работает:@getBankXML[]
$result[]
$expired(false)
$cacheFile[/../data/cache/currency-rates.xml]
^try{
$result[^xdoc::create[^file::load[text;$cacheFile]]]
}{
$exception.handled(1)
}
^if(def $result){
$now[^date::now[]]
$nowDate[${now.year}-^now.month.format[%02d]-^now.day.format[%02d]]
$rateDate[^result.documentElement.selectString[string(@Date)]]
$rateDate[^rateDate.mid(6;4)-^rateDate.mid(3;2)-^rateDate.mid(0;2)]
# we load rates only once per day, so we check cache mdate as
# rates are not updated on weekends and vacations.
^if($nowDate gt $rateDate){
$cacheStat[^file::stat[$cacheFile]]
$cache[$cacheStat.mdate]
$cacheDate[${cache.year}-^cache.month.format[%02d]-^cache.day.format[%02d]]
$expired($cacheDate ne $nowDate)
}
}
^if(!def $result || $expired){
^try{
$file[^file::load[text;http://www.cbr.ru/scripts/XML_daily.asp]]
$result[^xdoc::create[$file]]
^file.save[text;$cacheFile]
}{
$exception.handled(1)
}
}
^if(!def $result){
^throw[;Unable to load currency rates]
}