Created
November 12, 2012 20:43
-
-
Save swis/4061753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ParserAugsburg extends ParserBase | |
{ | |
protected $hintRegexChild = '/\(([\d]{1,2}|,|\s)+\)/i'; | |
protected $openingTimes = array( | |
'1' => array('start' => '1100', 'end' => '1400'), | |
'2' => array('start' => '1100', 'end' => '1400'), | |
'3' => array('start' => '1100', 'end' => '1400'), | |
'4' => array('start' => '1100', 'end' => '1400'), | |
'5' => array('start' => '1100', 'end' => '1330'), | |
'6' => array('start' => null, 'end' => null), | |
'7' => array('start' => null, 'end' => null) | |
); | |
protected $hints = array( | |
'1' => 'Farbstoff', | |
'2' => 'Geschmacksverstärker', | |
'3' => 'Konservierungsstoff', | |
'4' => 'Antioxidationsmittel', | |
'5' => 'geschwefelt', | |
'6' => 'geschwärzt', | |
'7' => 'gewachst', | |
'8' => 'Phosphat', | |
'9' => 'Süßungsmittel', | |
'10' => 'Phenylalaninquelle', | |
'10' => 'kann abführend wirken', | |
'12' => 'Schweinefleisch', | |
'13' => 'aus kontr. biol. Anbau', | |
'14' => 'Alkohol', | |
'15' => 'Rindfleisch', | |
'16' => 'gentechnisch verändert' | |
); | |
function parseSite() | |
{ | |
setlocale (LC_TIME, 'de_DE@euro', 'de_DE', 'de', 'ge'); | |
$html = htmlqp($this->url); | |
$menuRows = $html->find('table > tr'); | |
$i = 99; | |
foreach($menuRows as $menuRow) | |
{ | |
$menuCell = $menuRow->find('td:nth-child(2)'); | |
if ($menuCell->hasClass('textneu3')) | |
{ | |
$unparsedDate = $menuCell->text(); | |
$ftime = strptime(trim($unparsedDate), '%A, %d.%m.%Y'); | |
$date = mktime(0, 0, 0, $ftime['tm_mon'] + 1, $ftime['tm_mday'], $ftime['tm_year'] + 1900); | |
$i = 0; | |
} | |
if ($i < 25 && $i >= 1) | |
{ | |
$tdCount = $menuRow->end()->find('td')->size(); | |
if ($tdCount == 6 || $tdCount == 5) | |
{ | |
$cell = $menuRow->end()->find('td:nth-child(4)'); | |
$menuTitle = trim($cell->text(), "\x00..\x20\xA0\xC2\xC3"); | |
$menuPrice = $menuRow->end()->find('td:nth-child(5)')->text(); | |
} | |
elseif ($tdCount == 4) | |
{ | |
$cell = $menuRow->end()->find('td:nth-child(3)'); | |
if ($cell->hasClass('textneu2')) | |
{ | |
$menuTitle = trim($cell->text(), "\x00..\x20\xA0\xC2\xC3"); | |
$menuPrice = $menuRow->end()->find('td:nth-child(4)')->text(); | |
} | |
else | |
{ | |
$menuTitle = ''; | |
} | |
} | |
else | |
{ | |
$menuTitle = ''; | |
} | |
if (!empty($menuTitle)) | |
{ | |
$result = array(); | |
$result['day'] = date('Ymd', $date); | |
$result['time_from'] = $this->openingTimes[date('N', $date)]['start']; | |
$result['time_until'] = $this->openingTimes[date('N', $date)]['end']; | |
$result['minititle'] = 'Mensa'; | |
$result['title'] = $this->removeHints($menuTitle); | |
if (substr($result['title'], strlen($result['title']) - 11, 11) == '[CAFETERIA]') | |
{ | |
$result['title'] = trim(str_replace('[CAFETERIA]', '', $result['title'])); | |
$result['minititle'] = 'Mensa/ Cafeteria'; | |
} | |
$result['hints'] = $this->parseHints($menuTitle); | |
$sideDishes = explode('mit', $result['title']); | |
$result['title'] = $sideDishes[0]; | |
if (count($sideDishes) > 1) | |
{ | |
$sideDishes = preg_split ("/((\s)*,(\s)*)|(\s)+und(\s)+|(\s)+in(\s)+/", trim($sideDishes[1]), -1, PREG_SPLIT_NO_EMPTY); | |
$result['side_dishes'] = $sideDishes; | |
} | |
$titleTmp = explode('auf', $result['title']); | |
if (count($titleTmp) > 1) | |
{ | |
$result['title'] = trim($titleTmp[0]); | |
$result['subtitle'] = 'auf ' . trim($titleTmp[1]); | |
} | |
$menuPrice = explode('/', str_replace(',', '.', $menuPrice)); | |
$result['priceA'] = (float)$menuPrice[0]; | |
$result['priceB'] = (float)$menuPrice[1]; | |
$result['priceC'] = 2.0 * (float)$menuPrice[0]; | |
$this->parseResults[] = $result; | |
} | |
} | |
$i++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment