commit | author | age
|
8bd4d9
|
1 |
<?php
|
JK |
2 |
echo STAR.'Średnie kursy walut dodatkowych';
|
|
3 |
$link = @file_get_contents('http://www.nbp.pl/kursy/kursyb.html');
|
|
4 |
if(!$link) {
|
|
5 |
echo FAIL;
|
|
6 |
return FALSE;
|
|
7 |
}
|
|
8 |
|
|
9 |
$last = @file_get_contents('./B_last_link.txt');
|
|
10 |
|
|
11 |
$link = strstr($link, 'xml/');
|
|
12 |
$lnk = $link = '/kursy/'.substr($link, 0, strpos($link, '"'));
|
|
13 |
|
|
14 |
if($link == $last) {
|
|
15 |
echo NOT;
|
|
16 |
return TRUE;
|
|
17 |
}
|
|
18 |
|
|
19 |
$link = @file_get_contents('http://www.nbp.pl'.$link);
|
|
20 |
if(!$link) {
|
|
21 |
echo FAIL;
|
|
22 |
return FALSE;
|
|
23 |
}
|
|
24 |
|
|
25 |
$link = @simplexml_load_string($link);
|
|
26 |
if(!$link) {
|
|
27 |
echo FAIL;
|
|
28 |
return FALSE;
|
|
29 |
}
|
|
30 |
|
|
31 |
file_put_contents('./B_last_link.txt', $lnk);
|
|
32 |
unset($lnk);
|
|
33 |
|
|
34 |
$waluta['i_n_f_o']['tabela'] = (string)$link->numer_tabeli;
|
|
35 |
$waluta['i_n_f_o']['data'] = (string)$link->data_publikacji;
|
|
36 |
|
|
37 |
foreach($link->pozycja as $val) {
|
|
38 |
$key = (string)$val->kod_waluty;
|
|
39 |
$waluta[$key]['nazwa'] = (string)$val->nazwa_waluty;
|
|
40 |
$waluta[$key]['ilosc'] = (string)$val->przelicznik;
|
|
41 |
$waluta[$key]['kurs'] = (string)$val->kurs_sredni;
|
|
42 |
}
|
|
43 |
|
|
44 |
file_put_contents('./B_kursy.txt', serialize($waluta));
|
|
45 |
file_put_contents('./archiwum/B_'.date('j.m.Y', strtotime($waluta['i_n_f_o']['data'])).'.txt', serialize($waluta));
|
|
46 |
|
|
47 |
echo OK;
|
|
48 |
return TRUE;
|
|
49 |
?> |