コード例 #1
0
ファイル: ZlutaPumpa.php プロジェクト: erikfercak/Phood
 public function getMenu()
 {
     $menu = [];
     $headers = ['User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36'];
     $dom = hQuery::fromUrl('http://www.zluta-pumpa.info/denni-menu/', $headers);
     $food = $dom->find('div.post h4 strong');
     if ($food == NULL) {
         $food = $dom->find('div.post h4');
     }
     if ($food == NULL) {
         return $menu;
     }
     foreach ($food as $entry) {
         $entry = trim($entry->text(), " \t\n\r\v ");
         if (preg_match('~Polévka:\\s*(?:\\d\\.)?(.*)$~mui', $entry, $m)) {
             $menu['Polievky'][] = ['name' => $m[1], 'price' => 25];
         }
         if (preg_match('~Předkrm:(.*)$~mui', $entry, $m)) {
             $menu['Predkrm'][] = ['name' => preg_replace('~\\s+~u', ' ', trim($m[1])), 'price' => 0];
         }
         if (preg_match('~Hlavní jídlo:(?:\\s*\\d\\.\\s*)?(.*)$~mui', $entry, $m)) {
             $menu['Hlavne jedlo'][] = ['name' => preg_replace('~\\s+~u', ' ', trim($m[1])), 'price' => 99];
         }
     }
     return $menu;
 }
コード例 #2
0
ファイル: MlsnejKocour.php プロジェクト: erikfercak/Phood
 public function getMenu()
 {
     $menu = [];
     $dom = hQuery::fromUrl('http://www.mlsnejkocour.cz/');
     $cells = $dom->find('table.dailyMenuTable td');
     $section = 'N/A';
     $name = 'N/A';
     $price = 'N/A';
     foreach ($cells as $cell) {
         if ($cell->attr('colspan') == 3) {
             $section = $cell->find('h2:first');
             $section = preg_replace('~\\s+~u', ' ', $section);
             continue;
         }
         if ($cell->attr('class') == 'td-popis') {
             $name = $cell->text();
             $name = preg_replace('~\\s+~u', ' ', $name);
             continue;
         }
         if ($cell->attr('class') == 'td-cena') {
             $price = $cell->text();
             $menu[$section][] = ['name' => $name, 'price' => $price];
             $name = 'N/A';
             $price = 'N/A';
         }
     }
     foreach ($menu as $section => $unused) {
         if (!in_array($section, $this->wantedSections)) {
             unset($menu[$section]);
         }
     }
     return $menu;
 }
コード例 #3
0
ファイル: Ordr.php プロジェクト: erikfercak/Phood
 public function getMenu()
 {
     $menu = [];
     $dom = hQuery::fromUrl('https://www.ordr.cz/');
     $food = $dom->find('div.meal__desc-inner');
     foreach ($food as $entry) {
         $name = $entry->find('h2.meal__name')->text();
         $price = $entry->find('p.meal__price')->text();
         if (preg_match('~Cena (\\d+) Kč~u', $price, $m)) {
             $price = $m[1];
         }
         $menu['Menu'][] = ['name' => $name, 'price' => $price];
     }
     return $menu;
 }
コード例 #4
0
ファイル: Kravin.php プロジェクト: erikfercak/Phood
 public function getMenu()
 {
     $menu = [];
     $dom = hQuery::fromUrl('http://www.restauracekravin.cz/');
     $soups = $dom->find('div.entry-content td>strong');
     foreach ($soups as $soup) {
         if (preg_match('~(.*) \\(.+ (\\d+),-\\)$~ui', trim($soup->text(), " \t\n\r\v "), $m)) {
             $menu['Polievka'][] = ['name' => $m[1], 'price' => $m[2]];
         }
     }
     $food = $dom->find('div.entry-content li>strong');
     foreach ($food as $entry) {
         if (preg_match('~Menu č.\\d (.*) (\\d+),-$~ui', trim($entry->text(), " \t\n\r\v "), $m)) {
             $menu['Menu'][] = ['name' => $m[1], 'price' => $m[2]];
         }
     }
     return $menu;
 }
コード例 #5
0
ファイル: RetroMusicHall.php プロジェクト: erikfercak/Phood
 public function getMenu()
 {
     $menu = [];
     $dom = hQuery::fromUrl('https://www.zomato.com/widgets/daily_menu.php?entity_id=16506269');
     $divs = $dom->find('div.tmi.tmi-daily');
     $section = 'N/A';
     $name = 'N/A';
     $price = 'N/A';
     if (!$divs) {
         return $menu;
     }
     foreach ($divs as $div) {
         if (preg_match('~bold~', $div->attr('class'))) {
             $section = $div->find('div.tmi-name:first');
             $section = trim($section->text());
             continue;
         } else {
             $name = $div->find('div.tmi-name:first');
             $name = trim($name->text());
             $price = $div->find('div.tmi-price');
             $price = trim($price->text());
             if (preg_match('~^(\\d+)~u', $price, $m)) {
                 $price = $m[1];
             }
             if (empty($price)) {
                 $menu[$section][count($menu[$section]) - 1]['name'] .= ' ' . $name;
             } else {
                 $menu[$section][] = ['name' => $name, 'price' => $price];
             }
             $name = 'N/A';
             $price = 'N/A';
         }
     }
     foreach ($menu as $section => $unused) {
         if (!in_array($section, $this->wantedSections)) {
             unset($menu[$section]);
         }
     }
     return $menu;
 }
コード例 #6
0
ファイル: Phood.php プロジェクト: erikfercak/Phood
<?php

namespace Phood;

use duzun\hQuery;
require_once __DIR__ . '/vendor/duzun/hquery/hquery.php';
require_once __DIR__ . '/Restaurants/IRestaurant.php';
require_once __DIR__ . '/Restaurants/Kravin.php';
require_once __DIR__ . '/Restaurants/MlsnejKocour.php';
require_once __DIR__ . '/Restaurants/Ordr.php';
require_once __DIR__ . '/Restaurants/RetroMusicHall.php';
require_once __DIR__ . '/Restaurants/ZlutaPumpa.php';
hQuery::$cache_path = __DIR__ . '/cache';
function renderMenu(Restaurants\IRestaurant $restaurant)
{
    printf("\n%s\n%s", $restaurant->getTitle(), str_repeat('=', mb_strlen($restaurant->getTitle())));
    foreach ($restaurant->getMenu() as $section => $entries) {
        printf("\n%s\n%s\n", $section, str_repeat('-', mb_strlen($section)));
        foreach ($entries as $entry) {
            printf("%s %d,-\n", $entry['name'], $entry['price']);
        }
    }
}
$availableRestaurants = array('kravin', 'kocour', 'ordr', 'retro', 'pumpa');
$options = getopt('', $availableRestaurants);
$restaurants = array();
foreach ($options as $restaurant => $nothing) {
    if (in_array($restaurant, $availableRestaurants)) {
        $restaurants[] = $restaurant;
    }
}