1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,74 @@ |
0 |
+<?php |
|
1 |
+ |
|
2 |
+/** |
|
3 |
+ * Lebo bez masa nie je den dnom. Maso je sucast jedla, preto chodim jest do |
|
4 |
+ * blizkych malych restauracii. |
|
5 |
+ */ |
|
6 |
+ |
|
7 |
+$sites = [ |
|
8 |
+ 'Pulitzer' => 'http://pulitzer.sk/', |
|
9 |
+ 'Twenties' => 'http://www.twenties.sk/' |
|
10 |
+]; |
|
11 |
+ |
|
12 |
+$xpaths = [ |
|
13 |
+ 'Pulitzer' => [ |
|
14 |
+ 'Polievky' => '//*[@id="soups"]', |
|
15 |
+ 'Hlavne zradla' => '//*[@id="meals"]' |
|
16 |
+ ], |
|
17 |
+ 'Twenties' => [ |
|
18 |
+ 'Polievka + hlavne zradla' => '//*[@id="article"]/div[2]/p[1]' |
|
19 |
+ ] |
|
20 |
+]; |
|
21 |
+ |
|
22 |
+$output_file = '/tmp/results.php'; |
|
23 |
+file_put_contents($output_file, ''); |
|
24 |
+ |
|
25 |
+$dom = new DOMDocument(); |
|
26 |
+ |
|
27 |
+foreach ($sites as $restaurant => $site) |
|
28 |
+{ |
|
29 |
+ @$dom->loadHTML(file_get_contents($site)); |
|
30 |
+ $xpath_obj = new DOMXPath($dom); |
|
31 |
+ |
|
32 |
+ append_result('V tovarni na jedlo s nazvom *' . $restaurant . "* maju dneska toto: \n"); |
|
33 |
+ |
|
34 |
+ foreach ($xpaths[$restaurant] as $human_meal => $xpath) |
|
35 |
+ { |
|
36 |
+ append_result("\t$human_meal:\n"); |
|
37 |
+ |
|
38 |
+ $oh_my_god_here_are_saved_meals = $xpath_obj->query($xpath); |
|
39 |
+ if ($oh_my_god_here_are_saved_meals === FALSE |
|
40 |
+ OR $oh_my_god_here_are_saved_meals->length === 0) |
|
41 |
+ { |
|
42 |
+ continue; |
|
43 |
+ } |
|
44 |
+ |
|
45 |
+ $found_meal = FALSE; |
|
46 |
+ foreach ($oh_my_god_here_are_saved_meals->item(0)->childNodes as $elem) |
|
47 |
+ { |
|
48 |
+ $meal_meal_meal = trim($elem->nodeValue); |
|
49 |
+ if (! empty($meal_meal_meal)) |
|
50 |
+ { |
|
51 |
+ append_result("\t\t$meal_meal_meal\n"); |
|
52 |
+ $found_meal = TRUE; |
|
53 |
+ } |
|
54 |
+ } |
|
55 |
+ |
|
56 |
+ if (! $found_meal) |
|
57 |
+ { |
|
58 |
+ append_result("\tNevaria!!! Daj mi niekto gulomet, nech ich zabijem!\n"); |
|
59 |
+ } |
|
60 |
+ else |
|
61 |
+ { |
|
62 |
+ append_result("\n"); |
|
63 |
+ } |
|
64 |
+ } |
|
65 |
+} |
|
66 |
+ |
|
67 |
+append_result("\n\nMake me better on http://git.cinan.sk/obedparser.git/ :) \n"); |
|
68 |
+ |
|
69 |
+function append_result($text) |
|
70 |
+{ |
|
71 |
+ global $output_file; |
|
72 |
+ file_put_contents($output_file, $text, FILE_APPEND | FILE_TEXT); |
|
73 |
+} |