Created
October 11, 2016 13:20
-
-
Save havvg/426dce4fedf92e9a483178d190f5e418 to your computer and use it in GitHub Desktop.
Diesel price of JET petrol station in Penzberg (melody script)
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 | |
<<<CONFIG | |
packages: | |
- "fabpot/goutte: ^3.1" | |
- "symfony/console: ^3.1" | |
CONFIG; | |
use Goutte\Client; | |
use Symfony\Component\Console\Input\ArrayInput; | |
use Symfony\Component\Console\Output\ConsoleOutput; | |
use Symfony\Component\Console\Style\SymfonyStyle; | |
use Symfony\Component\DomCrawler\Crawler; | |
$page = 'http://www.clever-tanken.de/tankstelle_details/2039'; | |
$client = new Client(); | |
$crawler = $client->request('GET', $page); | |
$price = (float) trim($crawler->filter('.fuel-price-entry .price-field > span')->text()); | |
switch ($price) { | |
case ($price >= 1.10): | |
$highlight = 'fg=red'; | |
break; | |
case ($price <= 1.05): | |
$highlight = 'fg=yellow'; | |
break; | |
case ($price < 1): | |
$highlight = 'fg=green'; | |
break; | |
default: | |
$highlight = 'fg=white'; | |
break; | |
} | |
$updateInfo = trim($crawler->filter('.fuel-price-header')->text()); | |
preg_match('/Letzte Aktualisierung: (.*)/', $updateInfo, $matches); | |
$io = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()); | |
$io->writeln(sprintf('<%3$s>%1$02.2f EUR</%3$s> (%2$s)', $price, $matches[1], $highlight)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment