commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
echo STAR.'Pobieranie danych...'; |
|
3 |
|
|
4 |
class lotto { |
|
5 |
protected $strona = NULL; |
|
6 |
|
|
7 |
protected $gry = array( |
|
8 |
'lotto' => array(6, FALSE, 'dl'), |
|
9 |
'mini-lotto' => array(5, FALSE, 'el'), |
|
10 |
'kaskada' => array(12, FALSE, 'ka'), |
|
11 |
'multi-multi' => array(20, TRUE, 'mm'), |
|
12 |
'joker' => array(5, FALSE, 'jk') |
|
13 |
); |
|
14 |
|
|
15 |
function __construct() { |
|
16 |
$cache = 'lotto_cache.txt'; |
|
17 |
|
|
18 |
if( ( !file_exists($cache) AND !is_writable(dirname($cache)) ) |
|
19 |
OR ( file_exists($cache) AND !(is_writable($cache)) ) ) { |
|
20 |
$cache = ''; |
|
21 |
} |
|
22 |
else |
|
23 |
{ |
|
24 |
if(@filemtime($cache)<strtotime('yesterday 22:45') && time()<=strtotime('14:30')) { |
|
25 |
$recent = FALSE; |
|
26 |
} |
|
27 |
elseif( ( time()>=strtotime('14:30') && @filemtime($cache)<strtotime('14:30') ) |
|
28 |
OR ( time()>=strtotime('22:45') && @filemtime($cache)<strtotime('22:45') ) ) { |
|
29 |
$recent = FALSE; |
|
30 |
} |
|
31 |
else |
|
32 |
{ |
|
33 |
$recent = TRUE; |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
if($cache == '' OR !$recent) { |
|
38 |
$this->strona = @file_get_contents('http://lotto.pl/wyniki-gier'); |
|
39 |
if(!$this->strona) { |
|
40 |
throw new Exception('Nie udało się pobrać wyników.'); |
|
41 |
} |
|
42 |
|
|
43 |
if($cache != '') { |
|
44 |
file_put_contents($cache, $this->strona); |
|
45 |
} |
|
46 |
} |
|
47 |
else |
|
48 |
{ |
|
49 |
$this->strona = file_get_contents($cache); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
protected function szukaj_poczatku($tresc, $poczatek = 0) { |
|
54 |
return strpos($this->strona, $tresc, $poczatek); |
|
55 |
} |
|
56 |
|
|
57 |
protected function szukaj_konca($tresc, $poczatek = 0) { |
|
58 |
$pozycja = strpos($this->strona, $tresc, $poczatek); |
|
59 |
|
|
60 |
if($pozycja !== FALSE) { |
|
61 |
$pozycja += strlen($tresc); |
|
62 |
} |
|
63 |
|
|
64 |
return $pozycja; |
|
65 |
} |
|
66 |
|
|
67 |
function wynik($gra = 'lotto') { |
|
68 |
$wyniki = $this->wyniki($gra, 1); |
|
69 |
return $wyniki[0]; |
|
70 |
} |
|
71 |
|
|
72 |
function wyniki($gra = 'lotto', $liczba = 100) { |
|
73 |
if(!isset($this->gry[$gra])) { |
|
74 |
throw new Exception('Podana gra liczbowa nie jest obsługiwana.'); |
|
75 |
} |
|
76 |
|
|
77 |
$wyniki = array(); |
|
78 |
$poczatek = $this->szukaj_konca('<div class="start-wyniki_'.$gra.'">'); |
|
79 |
if($poczatek === FALSE) { |
|
80 |
throw new Exception('Nie znaleziono wyników dla gry '.$gra.' na stronie.'); |
|
81 |
} |
|
82 |
|
|
83 |
for($l = 0; $l < $liczba; $l++) { |
|
84 |
$poczatek = $this->szukaj_konca('<div class="wyniki_data">', $poczatek); |
|
85 |
if($poczatek === FALSE) { |
|
86 |
break; |
|
87 |
} |
|
88 |
|
|
89 |
$wynik = array(); |
|
90 |
|
|
91 |
$poczatek = $this->szukaj_konca('<strong>', $poczatek); |
|
92 |
if($poczatek === FALSE) { |
|
93 |
break; |
|
94 |
} |
|
95 |
$koniec = $this->szukaj_poczatku('</strong>', $poczatek); |
|
96 |
$wynik['data'] = substr($this->strona, $poczatek, $koniec-$poczatek); |
|
97 |
if($poczatek === FALSE) { |
|
98 |
break; |
|
99 |
} |
|
100 |
$poczatek = $this->szukaj_konca('<strong>', $poczatek); |
|
101 |
$koniec = $this->szukaj_poczatku('</strong>', $poczatek); |
|
102 |
$wynik['godzina'] = substr($this->strona, $poczatek, $koniec-$poczatek); |
|
103 |
|
|
104 |
$poczatek = $this->szukaj_konca('<div class="glowna_wyniki_'.$gra.'">', $poczatek); |
|
105 |
if($poczatek === FALSE) { |
|
106 |
break; |
|
107 |
} |
|
108 |
|
|
109 |
$wynik['liczby'] = array(); |
|
110 |
for($i = 0; $i < $this->gry[$gra][0]; $i++) { |
|
111 |
$poczatek = $this->szukaj_konca('<div class="wynik_'.$gra.'">', $poczatek); |
|
112 |
$koniec = $this->szukaj_poczatku('</div>', $poczatek); |
|
113 |
$wynik['liczby'][] = substr($this->strona, $poczatek, $koniec-$poczatek); |
|
114 |
} |
|
115 |
|
|
116 |
if($this->gry[$gra][1]) { |
|
117 |
$poczatek = $this->szukaj_konca('<div class="wynik_'.$gra.'_plus">', $poczatek); |
|
118 |
$koniec = $this->szukaj_poczatku('</div>', $poczatek); |
|
119 |
$wynik['plus'] = substr($this->strona, $poczatek, $koniec-$poczatek); |
|
120 |
} |
|
121 |
|
|
122 |
$wyniki[] = $wynik; |
|
123 |
} |
|
124 |
|
|
125 |
return $wyniki; |
|
126 |
} |
|
127 |
|
|
128 |
function pobierz() { |
|
129 |
foreach($this->gry as $gra => $data) { |
|
130 |
echo STAR.'Wyniki gry '.$gra.'...'; |
|
131 |
if($gra == 'multi-multi') { |
|
132 |
$wyniki = $this->wyniki($gra, 2); |
|
133 |
$wynik = $wyniki[0]; |
|
134 |
$skrot = $data[2].substr($wynik['godzina'], 0, 2); |
|
135 |
$last_data = @file_get_contents('./last_'.$skrot.'.txt'); |
|
136 |
if($last_data != $wynik['data']) { |
|
137 |
$output = array(); |
|
138 |
$output['data'] = $wynik['data']; |
|
139 |
for($i = 0; $i < $data[0]; $i++) { |
|
140 |
$output[$i+1] = $wynik['liczby'][$i]; |
|
141 |
} |
|
142 |
if($data[1]) { |
|
143 |
$output['plus'] = $wynik['plus']; |
|
144 |
} |
|
145 |
file_put_contents('./last_'.$skrot.'.txt', $output['data']); |
|
146 |
file_put_contents('./'.$skrot.'.txt', serialize($output)); |
|
147 |
file_put_contents('./archiwum/'.$skrot.'_'.date('j.m.Y', strtotime($output['data'])).'.txt', serialize($output)); |
|
148 |
} |
|
149 |
|
|
150 |
$wynik = $wyniki[1]; |
|
151 |
$skrot = $data[2].substr($wynik['godzina'], 0, 2); |
|
152 |
$last_data = @file_get_contents('./last_'.$skrot.'.txt'); |
|
153 |
if($last_data != $wynik['data']) { |
|
154 |
$output = array(); |
|
155 |
$output['data'] = $wynik['data']; |
|
156 |
for($i = 0; $i < $data[0]; $i++) { |
|
157 |
$output[$i+1] = $wynik['liczby'][$i]; |
|
158 |
} |
|
159 |
if($data[1]) { |
|
160 |
$output['plus'] = $wynik['plus']; |
|
161 |
} |
|
162 |
file_put_contents('./last_'.$skrot.'.txt', $output['data']); |
|
163 |
file_put_contents('./'.$skrot.'.txt', serialize($output)); |
|
164 |
file_put_contents('./archiwum/'.$skrot.'_'.date('j.m.Y', strtotime($output['data'])).'.txt', serialize($output)); |
|
165 |
} |
|
166 |
} |
|
167 |
else |
|
168 |
{ |
|
169 |
$wynik = $this->wynik($gra); |
|
170 |
$skrot = $data[2]; |
|
171 |
$last_data = @file_get_contents('./last_'.$skrot.'.txt'); |
|
172 |
if($last_data != $wynik['data']) { |
|
173 |
$output = array(); |
|
174 |
$output['data'] = $wynik['data']; |
|
175 |
for($i = 0; $i < $data[0]; $i++) { |
|
176 |
$output[$i+1] = $wynik['liczby'][$i]; |
|
177 |
} |
|
178 |
if($data[1]) { |
|
179 |
$output['plus'] = $wynik['plus']; |
|
180 |
} |
|
181 |
file_put_contents('./last_'.$skrot.'.txt', $output['data']); |
|
182 |
file_put_contents('./'.$skrot.'.txt', serialize($output)); |
|
183 |
file_put_contents('./archiwum/'.$skrot.'_'.date('j.m.Y', strtotime($output['data'])).'.txt', serialize($output)); |
|
184 |
} |
|
185 |
} |
|
186 |
echo OK; |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
$lotto = new lotto(); |
|
192 |
echo OK; |
|
193 |
|
|
194 |
$lotto->pobierz(); |
|
195 |
?> |